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?
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With