Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass command line Params in mvn exec:exec

Tags:

maven-plugin

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?

like image 399
deckingraj Avatar asked Mar 22 '11 19:03

deckingraj


People also ask

What is mvn exec exec?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

How do I run an argument in a maven project?

You could run: mvn exec:exec -Dexec. args="arg1". This will pass the argument arg1 to your program. By using the -f parameter, you can also run it from other directories.

What is P option in maven?

A reference tells us that -P specifies which profile Maven is to run under. Projects can define multiple profiles which may pull in different dependencies, so this is required if you have a project that can do that.

What is mvn exec Java?

mvn exec:java is a goal from the exec plugin for maven. It lets you specify a main class to execute (see pom. xml). This lets you avoid having to figure out the proper java command to run and classpath arguments and the like.


2 Answers

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.

like image 171
codemule Avatar answered Sep 21 '22 15:09

codemule


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> 
like image 21
jcadcell Avatar answered Sep 19 '22 15:09

jcadcell