Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass systemProperties when invoking exec:java plugin in maven?

Tags:

I want to use the exec:java plugin to invoke the main class from command line. I can pass arguments from the command line using -Dexec.args="arg0 arg1 arg2", I don't know how to pass system properties. I tried '-Dexec.systemProperties="key=value"` but with no effect.

pom.xml looks like this:

  <plugin>       <groupId>org.codehaus.mojo</groupId>     <artifactId>exec-maven-plugin</artifactId>     <configuration>       <mainClass>ibis.structure.Structure</mainClass>     </configuration>     </plugin> 
like image 234
Alexandru Avatar asked Sep 14 '10 12:09

Alexandru


People also ask

How do I pass system properties in maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

What is Mvn exec Java?

mvn exec:java is a goal from the exec plugin for maven. It lets you specify a main class to execute (see pom. xml). This lets you avoid having to figure out the proper java command to run and classpath arguments and the like.


2 Answers

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> 
like image 119
mokshino Avatar answered Oct 08 '22 16:10

mokshino


There is no way to set the <systemProperties> parameter on the command line.

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.

mvn -Dkey=value exec:java -Dexec.mainClass=com.yourcompany.yourclass \     -Dexec.args="arg1 arg2 arg3" 
like image 35
Sean Patrick Floyd Avatar answered Oct 08 '22 16:10

Sean Patrick Floyd