Pass command line Params in mvn exec:exec

Two ways to pass command line arguments into mvn:exec:

Method 1, on the command line:

mvn exec:java -Dexec.mainClass="com.myPackage.myClass" -Dexec.args="command line arguments"

Method 2, in the maven POM file:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <configuration>
        <mainClass>com.myPackage.myClass</mainClass>
        <commandlineArgs>command line arguments</commandlineArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

Then on the command line all you have to do is run:

mvn exec:java

Good luck.


I was able to get JVM args working for exec:exec using the following after reading this article:

    <build>
      <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-Dhttp.proxyHost=myproxy.example.com</argument>
                    <argument>-Dhttp.proxyPort=8080</argument>
                    <argument>-classpath</argument>
                    <classpath />
                    <argument>com.example.Main</argument>
                </arguments>
            </configuration>
        </plugin>
      </plugins>
    </build>

why not use system property?

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.3.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>bobo.Abc</mainClass>
                  <arguments>
                        <argument>argument1</argument>
                    </arguments>
                    <systemProperties>
                        <systemProperty>
                            <key>jvmProperty1</key>
                            <value>dev</value>
                        </systemProperty>
                    </systemProperties>
                </configuration>
            </plugin>

Tags:

Maven Plugin