mavenmaven-3maven-pluginjvm-argumentsexec-maven-plugin

How to set both VM Params and Program args using exec-maven-plugin?


I am using exec-maven-plugin to run java app. I need to pass both JVM params and program arguments. I am setting JVM params like this:

<artifactId>exec-maven-plugin</artifactId>
       <version>1.6.0</version>
           <executions>
               <execution>
                   <id>MyId</id>
                   <goals>
                       <goal>java</goal>
                   </goals>
                   <configuration>
                       <mainClass>MyClass</mainClass>
                       <arguments>
                           <argument>-XX:+UseG1GC</argument>
                           <argument>-Xms2G</argument>
                           <argument>-Xmx2G</argument>                                    
                       </arguments>
                   </configuration>
               </execution>

...

and run the program:

mvn exec:java@MyId  -Dexec.args="my params"

However it looks like arguments set in pom.xml are not used and overwritten by -Dexec.args, and section is used only as program arguments.

Tried to add into arguments (as shown in this article), but ran into

Unable to parse configuration of mojo org.codehaus.mojo:exec-maven-plugin:1.6.0:java for parameter arguments: Cannot store value into array:
ArrayStoreException -> [Help 1]

Found similar unresolved problem on jboss.org.

Any suggestions?


Solution

  • Found the answer for my question on the plugin page - at the very end of it.

    This goal helps you run a Java program within the same VM as Maven.

    The goal goes to great length to try to mimic the way the VM works, but there are some small subtle differences. Today all differences come from the way the goal deals with thread management.

    Note: The java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the MAVEN_OPTS environment variable.

    That doesn't work for me, so switching to mvn exec:exec mode. works for JVM params there.

    Found a solution here: Using Maven 'exec:exec' with Arguments