Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 311
Tatiana Didik Avatar asked May 09 '18 19:05

Tatiana Didik


People also ask

What are the goals of the Exec Maven plugin?

The plugin provides 2 goals to help execute system and Java programs. General information about the goals. exec:exec execute programs and Java programs in a separate process. exec:java execute Java programs in the same VM. General instructions on how to use the Exec Maven Plugin can be found on the usage page.

How do I pass an argument to Maven from terminal?

Passing an Argument to Maven Now, let's run Maven from our terminal as we usually do, with the package command, for example. But in this case, let's also add the notation -D followed by a property name: Maven will use the value (2.5) passed as an argument to replace the COMMON_VERSION_CMD property set in our pom.xml.

How to pass JVM parameters to an executed class in Maven?

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.

What is the difference between MVN Exec and exec Java in Maven?

Normally I would use mvn exec:java to run a Java program, but exec:java runs applications in the same JVM as Maven, which prevents me from modifying the classpath. Since the native dependencies must be added to the classpath, I am forced to use mvn exec:exec instead. This is the relevant snippet of the pom:


1 Answers

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

like image 165
Tatiana Didik Avatar answered Sep 19 '22 11:09

Tatiana Didik