Pass command line Params in mvn exec:exec

deckingraj picture deckingraj · Mar 22, 2011 · Viewed 46.9k times · Source

I am amazed that what should have been a very easy job is turning into a very annoying task for me. All i need is to pass few command line parameters to my maven exec:exec plugin. unfortunately hours of googling has not helped at all.

Here is my plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-instrument</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-classpath</argument>
            <classpath />
            <argument>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argument>
            <argument>-Xmx256m</argument>
            <argument>com.myPackage.Myclass</argument>
        </arguments>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Now from the command prompt i am typing in:

mvn exec:exec -Dexec.args=-Dmy.property=myProperty

I also tried:

mvn exec:exec -Dexec.arguments=-Dmy.property=myProperty

And many other things. However nothing seems to be working. I know that exec:exec runs in a separate VM but as per the documentation -Dexec.args should work for me. Can someone please suggest where i am going wrong?

Answer

codemule picture codemule · May 15, 2014

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.