[英]How to pass systemProperties when invoking exec:java plugin in maven?
I want to use the exec:java plugin to invoke the main class from command line. 我想使用exec:java插件从命令行调用主类。 I can pass arguments from the command line using
-Dexec.args="arg0 arg1 arg2"
, I don't know how to pass system properties. 我可以使用
-Dexec.args="arg0 arg1 arg2"
从命令行传递参数,我不知道如何传递系统属性。 I tried '-Dexec.systemProperties="key=value"` but with no effect. 我试过'-Dexec.systemProperties =“key = value”`但没有效果。
pom.xml
looks like this: pom.xml
看起来像这样:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>ibis.structure.Structure</mainClass>
</configuration>
</plugin>
Try following for me it works properly 尝试跟我说它工作正常
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>ibis.structure.Structure</mainClass>
<systemProperties>
<systemProperty>
<key>someKey</key>
<value>someValue</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
There is no way to set the <systemProperties>
parameter on the command line. 无法在命令行上设置
<systemProperties>
参数 。
However, since exec:java
is not forked, you can just pass a system property to maven and it will be picked up by exec:java
as well. 但是,由于
exec:java
不是分叉的,你可以只将系统属性传递给maven,它也会被exec:java
选中。
mvn -Dkey=value exec:java -Dexec.mainClass=com.yourcompany.yourclass \
-Dexec.args="arg1 arg2 arg3"
I just ran into a similar problem and I wanted to write a full answer for others that might come across this question. 我刚遇到类似的问题,我想为可能遇到这个问题的其他人写一个完整的答案。
Even though the question is not about pom.xml but about command line - it does not state how to do the same with pom.xml so here it is 即使问题不是关于pom.xml而是关于命令行 - 它没有说明如何对pom.xml做同样的事情,所以这里是
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>myPackage.MyMain</mainClass>
<systemProperties>
<property>
<key>myKey</key>
<value>myValue</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
For the command line - I think Sean Patrick Floyd's
answer is good - however, if you have something already defined in your pom.xml it will override it. 对于命令行 - 我认为
Sean Patrick Floyd's
答案很好 - 但是,如果你已经在你的pom.xml中定义了一些东西,那么它将覆盖它。
So running 好跑
mvn exec:java -DmyKey=myValue
should also work for you. 也应该适合你。
You should also note that the exec plugin's documentations states the following 您还应该注意, 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.
So you can also do something like this 所以你也可以这样做
export MAVEN_OPTS=-DmyKey=myValue
mvn exec:java
and it should work the same way. 它应该以同样的方式工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.