【发布时间】:2011-07-07 10:05:01
【问题描述】:
如何在jetty-maven-plugin 中启用assertions?默认情况下它们被禁用。
【问题讨论】:
标签: java maven-2 maven jetty assertions
如何在jetty-maven-plugin 中启用assertions?默认情况下它们被禁用。
【问题讨论】:
标签: java maven-2 maven jetty assertions
将环境变量MAVEN_OPTS 设置为-ea。 Jetty 默认在 Maven 进程中运行,因此受此设置的影响。
还有一个有趣的库称为Force Assertions,它与Java 1.6 编译过程挂钩。在编译期间,所有assert cond : detail; 都被透明地编译为if (!cond) throw new Assertion(detail); 块,这意味着无论JVM 参数是什么,断言都将始终有效。值得一看。
【讨论】:
pom.xml内部做同样的事情?
如果您使用的是 Netbeans(使用 Netbeans 8.0 测试),这是 imo 的方法:
将此添加到您的 nbactions.xml 文件(在项目根目录中):
<actions>
<action>
<actionName>CUSTOM-jetty:run</actionName>
<displayName>jetty:run</displayName>
<goals>
<goal>jetty:run</goal>
</goals>
<properties>
<Env.MAVEN_OPTS>-ea</Env.MAVEN_OPTS>
</properties>
</action>
</actions>
无需其他设置。你可以使用 jetty:run。
【讨论】:
如果它只是运行测试并且你正在使用 maven-surefire-plugin,使用这个
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<enableAssertions>true</enableAssertions>
</configuration>
</plugin>
【讨论】: