如何在maven中调用exec:java插件时传递systemProperties?
我想使用exec:java插件从命令行调用主类。 我可以使用-Dexec.args="arg0 arg1 arg2"
从命令行传递参数,我不知道如何传递系统属性。 我试过’-Dexec.systemProperties =“key = value”`但没有效果。
pom.xml
看起来像这样:
org.codehaus.mojo exec-maven-plugin ibis.structure.Structure
无法在命令行上设置
参数 。
但是,由于exec:java
不是分叉的,你可以只将系统属性传递给maven,它也会被exec:java
选中。
mvn -Dkey=value exec:java -Dexec.mainClass=com.yourcompany.yourclass \ -Dexec.args="arg1 arg2 arg3"
尝试跟着我,它工作正常
org.codehaus.mojo exec-maven-plugin ibis.structure.Structure someKey someValue
我刚遇到类似的问题,我想为可能遇到这个问题的其他人写一个完整的答案。
即使问题不是关于pom.xml而是关于命令行 – 它没有说明如何对pom.xml做同样的事情所以这里是
org.codehaus.mojo exec-maven-plugin 1.2.1 java myPackage.MyMain myKey myValue
对于命令行 – 我认为Sean Patrick Floyd's
答案很好 – 但是,如果你已经在你的pom.xml中定义了一些东西,那么它将覆盖它。
好跑
mvn exec:java -DmyKey=myValue
也应该适合你。
您还应该注意, exec插件的文档说明如下
A list of system properties to be passed. Note: as the execution is not forked, some system properties required by the JVM cannot be passed here. Use MAVEN_OPTS or the exec:exec instead. See the user guide for more information.
所以你也可以这样做
export MAVEN_OPTS=-DmyKey=myValue mvn exec:java
它应该以同样的方式工作。