6

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

Community
  • 1
  • 1
Ravi Sahu
  • 890
  • 1
  • 11
  • 24
  • try `mvn exec:java -DmainClass="com.text.Test"` – jmj Dec 17 '14 at 04:53
  • @JigarJoshi Its running with mvn exec:java -Dexec.mainClass="com.test.Test", but I want to VM arguments but not by MAVEN_OPTS – Ravi Sahu Dec 17 '14 at 04:55
  • you can pass VM argument by `-Dexec.args="-X_____"` – jmj Dec 17 '14 at 04:59
  • @JigarJoshi there are 2 problems here **1)how can i pass parameters to java, see it asked me to pass java parameters?**
    **2) how can i pass arguments?**
    – Ravi Sahu Dec 17 '14 at 05:02
  • you mean command line parameter to main or parameter to JVM itself, for JVM see my above comment – jmj Dec 17 '14 at 05:03
  • @JigarJoshi - I mean arguments to JVM, also do check my pom i think its not correct – Ravi Sahu Dec 17 '14 at 05:04
  • did you try ? – jmj Dec 17 '14 at 05:21
  • @JigarJoshi comments?, i din't get what u are trying to say – Ravi Sahu Dec 17 '14 at 05:23
  • can you try this once `mvn exec:java -DmainClass="com.text.Test" -Dexec.args="-X_____"` – jmj Dec 17 '14 at 05:38
  • It is `mvn exec:java -Dexec.mainClass="com.test.Test" -Dexec.args="-XX:+PrintGCDetails"` – Ravi Sahu Dec 17 '14 at 05:42
  • yes [right](http://mojo.codehaus.org/exec-maven-plugin/usage.html), doesn;t it work ? – jmj Dec 17 '14 at 05:43
  • yes it works but `-XX:+PrintGCDetails` part dose not worked, i want to see GC logs – Ravi Sahu Dec 17 '14 at 05:45
  • can you from your main class print all system property to see actually it gets passed to JVM ? – jmj Dec 17 '14 at 05:46
  • it get passed i can see in output with other system properties `exec.args=-XX:+PrintGCDetails`. I guess its not applied to JVM because `exec:java execute Java programs in the same VM.` – Ravi Sahu Dec 17 '14 at 05:59
  • that makes sense, but why that parameter then if it is going to run on same JVM :-/ – jmj Dec 17 '14 at 06:05
  • check [http://mojo.codehaus.org/exec-maven-plugin/]. Thats why i was using exec:exec, it execute programs and Java programs in a separate process. – Ravi Sahu Dec 17 '14 at 06:07
  • can you invoke `mvn exec:exex .... -X`` with `-X` to see what command it under the cover executes ? – jmj Dec 17 '14 at 06:15
  • Already tried.. on `mvn exec:exec -Dexec.mainClass="com.test.Test" -Dexec.args="-XX:+PrintGCDetails" -X` prints `The parameters 'executable' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec are missing or invalid`,with lot of other unusefull lines(i think), check my pom now – Ravi Sahu Dec 17 '14 at 06:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67085/discussion-between-biker-and-jigar-joshi). – Ravi Sahu Dec 17 '14 at 06:23

1 Answers1

7
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

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438