如果行或分支覆盖率低于给定阈值,我正在尝试将WAR项目构建配置为失败.我一直在使用优秀的Java Power Tools书籍第455页提供的配置,但没有成功.这是我的项目Maven 2 POM的相关片段:
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<check>
<!-- Per-class thresholds -->
<lineRate>80</lineRate>
<branchRate>80</branchRate>
<!-- Project-wide thresholds -->
<totalLineRate>90</totalLineRate>
<totalBranchRate>90</totalBranchRate>
</check>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>coverage-tests</id>
<!-- The "verify" phase occurs just before "install" -->
<phase>verify</phase>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
<instrumentation>
<excludes>
<exclude>au/**/*Constants.*</exclude>
</excludes>
<ignores>
<ignore>au/**/*Constants.*</ignore>
</ignores>
</instrumentation>
</configuration>
</plugin>
...
</plugins>
...
</build>
Run Code Online (Sandbox Code Playgroud)
正如我所说,覆盖率报告工作正常,问题是如果线或分支覆盖率低于我指定的阈值,"安装"目标不会失败.有没有人有这个工作,如果是这样,你的POM是什么样的,你使用的是哪个版本的Cobertura和Maven?我正在使用Maven 2.0.9和Cobertura 2.2.
我已经尝试过谷歌搜索和阅读Cobertura文档,但没有运气(后者至少可以说是稀疏的).
我对java.sql.DatabaseMetaData界面很熟悉,但我发现它非常笨重.例如,为了找出表名,您必须使用众所周知的文字作为列名来调用getTables并循环返回ResultSet.
是否有更简单的方法来获取数据库元数据?
我是这个认证领域的新手.我搜索了很多,但无法找到一种方法来验证对Play服务器的REST调用.各种方式和最佳实践有哪些?
scala playframework scala-collections playframework-2.0 typesafe-activator
如果我从Oracle客户端(SQL Developer)运行它,则此SQL语句有效:
insert into Person (Name) select 'Bob' from dual
Run Code Online (Sandbox Code Playgroud)
如果我通过Spring JDBC发出它,而不使用KeyHolder,它也可以工作:
final PreparedStatementCreator psc = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException
{
return con.prepareStatement(
"insert into Person (Name) select 'Bob' from dual");
}
};
jdbcOperations.update(psc);
Run Code Online (Sandbox Code Playgroud)
但是我需要使用KeyHolder来获取新插入的行的ID.如果我改变上面的代码使用KeyHolder如下:
final KeyHolder keyHolder = new GeneratedKeyHolder();
final PreparedStatementCreator psc = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException
{
return con.prepareStatement(
"insert into Person (Name) select 'Bob' from dual",
new String[] {"PersonID"});
}
};
jdbcOperations.update(psc, …Run Code Online (Sandbox Code Playgroud) 我的Java应用程序需要知道本地机器上安装了哪个版本的IE(如果有的话),并且查询注册表似乎是最简单的方法.我应该查看哪个注册表项和值?
这需要在Windows XP,Windows Server 2003及更高版本上运行.
我在一些POJO中实现了一些域逻辑.我想编写一个Swing用户界面,以允许用户启动并查看各种域操作的结果.
UI和域之间通信的最佳模式/框架/库是什么?这归结为:
我知道MVC是一个广泛的概念,并且已经摆弄了Observer模式(如果我理解正确,它的Java实现有一些缺点),但我想知道这个问题是否有一个公认的最佳实践?
我有一个部署为EAR文件的J2EE应用程序,该文件又包含业务层代码(包括一些EJB)的JAR文件和Web层代码的WAR文件.EAR文件部署到JBoss 3.2.5,它解压缩EAR和WAR文件,但不解压缩JAR文件(这不是问题,只是FYI).
JAR文件中的一个文件是MS Word模板,其绝对路径需要传递给某些本机MS Word代码(使用Jacob,FWIW).
问题是,如果我尝试获取这样的文件(从JAR文件中的一些代码中):
URL url = getClass().getResource("myTemplate.dot");
File file = new File(url.toURI()); // <= fails!
String absolutePath = file.getAbsolutePath();
// Pass the absolutePath to MS Word to be opened as a document
Run Code Online (Sandbox Code Playgroud)
...然后java.io.File构造函数抛出IllegalArgumentException"URI不是分层的".URL和URI都具有相同的toString()输出,即:
jar:file:/G:/jboss/myapp/jboss/server/default/tmp/deploy/tmp29269myapp.ear-contents/myapp.jar!/my/package/myTemplate.dot
Run Code Online (Sandbox Code Playgroud)
这条路径的大部分在文件系统上是有效的,但其余路径不是(在JAR文件的内部):
G:/jboss/myapp/jboss/server/default/tmp/deploy/tmp29269myapp.ear-contents
Run Code Online (Sandbox Code Playgroud)
获取此文件的绝对路径最简单的方法是什么?
我正在尝试编写一个自定义JSPX标记,该标记从给定列表中的每个对象读取给定bean属性的值,该属性的名称作为JSP属性传递给标记.标签看起来像这样:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:jsp="http://java.sun.com/JSP/Page"
version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="items" type="java.lang.Iterable"
required="true" description="The items whose properties are to be read"
rtexprvalue="true"/>
<jsp:directive.attribute name="propertyName" type="java.lang.String"
required="true" description="The name of the bean property to read"
rtexprvalue="true"/>
<c:forEach items="${items}" var="item">
<!-- This is the bit that doesn't work -->
<jsp:getProperty name="item" property="${propertyName}" />
</c:forEach>
</jsp:root>
Run Code Online (Sandbox Code Playgroud)
问题是标签的property属性jsp:getProperty似乎不接受表达式,只接受文字值.所以这可行,但对我没用(因为我不知道属性名称,直到运行时):
<jsp:getProperty name="item" property="firstName" />
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
org.apache.jasper.JasperException: org.apache.jasper.JasperException:
PWC6054: Cannot find any information on property '${propertyName}' in
a bean of type 'com.example.FooBar'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我有一个使用EJB 2.x实体bean(BMP)的大型应用程序.众所周知,这是一种可怕的持久性策略(如果有必要,我可以详细说明).
我想开始迁移这个应用程序以使用更具表现力,透明和非侵入性的持久性策略,并且考虑到我公司以前使用它的经验,Hibernate 3.x是显而易见的选择.
迁移到Hibernate需要一段时间,因为应用程序中有超过100个表使用实体bean.所以我正在研究一种分阶段的方法,其中两个持久性策略并行运行,如果可能的话,理想情况下同时在同一个表上运行.
我的问题是,结合这两种持久性策略有哪些陷阱(如果有的话)?他们会互相帮助吗?
Tomcat 通过 JMX 提供各种监控操作。该文档描述了如何启用和禁用远程监控。但是是否可以禁用本地监控(即从部署到 Tomcat 本身的 Web 应用程序中)?
换句话说,我可以指望我的 webapp 总是能够MBeanServer使用(例如)获取本地JmxUtils#locateMBeanServer吗?