I am new to maven and facing problems while running a class file through maven
It runs fine with
mvn exec:java -Dexec.mainClass="com.test.Test"
But not with
mvn exec:exec -Dexec.executable=java -Dexec.mainClass="com.test.Test"
It asks for java parameters
F:\data\work\Test>mvn exec:exec -Dexec.executable=java -Dexec.mainClass="com.test.Test"
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
-hotspot is a synonym for the "server" VM [deprecated]
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
I am already providing a class file then why its not able to pick that? I tried providing those even through pom.
I am using exec:exec as I dont want to pass VM arguments from MAVEN_OPTS
here is my pom
<profiles>
<profile>
<id>fib</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<mainClass>com.test.Test</mainClass>
<executable>java</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
What am I missing?
So 2 questions which arises -
1)What am I missing s that its asking me to pass java parameters despite of passing mainClass?
2)How can I pass VM arguments using exec-maven-plugin?
I have found this for my 2nd question using maven 'exec:exec' with arguments
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.
In order to do this, we can use the exec-maven-plugin. To be more specific, the exec:java goal from this plugin executes the supplied Java class with the enclosing project's dependencies as the classpath. As shown above, we're using the exec. mainClass system property to pass the fully qualified class name.
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.
mvn exec:exec -Dexec.executable=java -Dexec.args="-classpath target/classes -XX:+PrintGCDetails com.test.Test"
also if you are concerned about dependencies being in classpath then make a fat jar and set it in classpath
interesting discussion: https://chat.stackoverflow.com/rooms/67085/discussion-between-biker-and-jigar-joshi
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