如何在jetty-maven-plugin中启用Java断言?
如何在 断言 “http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin”rel =“nofollow”>jetty-maven-plugin?默认情况下它们是禁用的。
How to enable assertions in jetty-maven-plugin? By default they are disabled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将环境变量
MAVEN_OPTS
设置为-ea
。 Jetty 默认在 Maven 进程中运行,因此受此设置的影响。还有一个有趣的库,名为 Force Assertions,它与 Java 1.6 编译挂钩过程。在编译期间,所有
assert cond :Detail;
都会透明地编译为if (!cond) throw new Assertion(detail);
块,这意味着无论 JVM 是什么,断言都将始终有效参数是。值得检查。Set environment variable
MAVEN_OPTS
to-ea
. Jetty by default runs within Maven process and thus is affected by this setting.There is also interesting library called Force Assertions which hooks into Java 1.6 compilation process. During compilation all
assert cond : detail;
are transparently compiled toif (!cond) throw new Assertion(detail);
blocks, which means assertions will work always no matter what JVM parameters are. Worth to check.请参阅:maven jetty 插件 - 如何控制 vm 参数?
See: maven jetty plugin - how to control vm arguments?
如果您使用的是 Netbeans(使用 Netbeans 8.0 进行测试),则在我看来,这是执行此操作的方法:
将其添加到您的 nbactions.xml 文件(在项目根目录中):
无需其他设置。你可以只使用jetty:run。
另请参阅https://netbeans.org/bugzilla/show_bug.cgi?id=166874
If your are using Netbeans (tested with Netbeans 8.0), this is the way to do it imo:
Add this to your nbactions.xml file (in the project root directory):
No other setup needed. You can just use jetty:run.
See also https://netbeans.org/bugzilla/show_bug.cgi?id=166874
如果只是运行测试并且您正在使用 maven-surefire-plugin,请使用此
If it's to only run tests and you are using maven-surefire-plugin, use this