[ACCEPTED]-How to pass systemProperties when invoking exec:java plugin in maven?-exec-maven-plugin

Accepted answer
Score: 26

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>

0

Score: 18

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

However, since exec:java is not forked, you 2 can just pass a system property to maven 1 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"
Score: 7

I just ran into a similar problem and I 12 wanted to write a full answer for others 11 that might come across this question.

Even 10 though the question is not about pom.xml 9 but about command line - it does not state 8 how to do the same with pom.xml so here 7 it is

    <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 6 is good - however, if you have something 5 already defined in your pom.xml it will 4 override it.

So running

 mvn exec:java -DmyKey=myValue

should also work 3 for you.

You should also note that the exec plugin's documentations states 2 the following

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 1 like this

export MAVEN_OPTS=-DmyKey=myValue
mvn exec:java

and it should work the same way.

More Related questions