[英]Enable assert in a maven built project
我有一个使用Maven构建的java程序,我需要启用assert
关键字。 理想情况下,我想在maven build命令中启用断言。
Maven编译并构建java代码。 当你实际运行java代码时会出现断言错误,所以使用maven你不能这样做
除非你使用maven插件来启动java代码,否则你必须提供-ea
到jvm
exec:java
将-ea
传递给命令行参数
万全
如果你的意思是测试执行,那么配置sure-fire插件将-ea
传递给jvm
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<enableAssertions>true</enableAssertions>
</configuration>
</plugin>
对我有用的唯一事情是
export MAVEN_OPTS="-ea"
您无法在启用断言的情况下构建应用程序,因为它们在运行时启用,具体取决于您是否将-ea
参数传递给JVM。 以下是maven exec插件的配置,它在运行程序时启用断言:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-ea</argument>
<argument>-classpath</argument> <classpath />
<argument>io.mc.validationdemo.App</argument>
</arguments>
</configuration>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.