在maven构建的项目中启用断言 [英] Enable assert in a maven built project

查看:976
本文介绍了在maven构建的项目中启用断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Maven构建的java程序,我需要启用 assert 关键字。理想情况下,我想在maven构建命令中启用断言。

I have a java program that is built using Maven and I need to enable the assert keyword. Ideally, I'd want to enable assertions in the maven build command.

推荐答案

Maven编译并构建java代码。当你实际运行java代码时出现断言错误,所以使用maven你不能这样做

Maven compiles and builds the java code. Assertion errors come when you are actually running java code so with maven you can't do it this way

除非你使用maven插件来启动java代码,否则你会有提供 -ea 到jvm

unless you are using maven plugin to launch java code, you would have to supply -ea to jvm

exec:java

exec:java

-ea 传递给命令行参数

Surefire

如果您打算执行测试,请配置sure-fire插件以传递 -ea 到jvm

if you meant for test execution then configure sure-fire plugin to pass -ea to jvm

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.16</version>
    <configuration>
        <enableAssertions>true</enableAssertions>
    </configuration>
  </plugin>

这篇关于在maven构建的项目中启用断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆