I have the following problem. I would like to run mvn
from command line for a Main.java
file. Main.java
accepts a parameter. How do I do that from command line?
I tried finding an example but I was not successful. Could someone help me by giving me an example of that?
I looked here but didn't quite understand what I should do.
Also, how do I execute that command from a different folder than the Main.java folder?
for example the Main.java
is located in my/java/program/Main.java
.
What should I put in
mvn exec:java -Dexec.mainClass="what to put here?" -Dexec.args="arg0 arg1 arg2"
In addition to running it with mvn exec:java
, you can also run it with mvn exec:exec
mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath your.package.MainClass"
Adding a shell script e.g. run.sh
makes it much more easier:
#!/usr/bin/env bash
export JAVA_PROGRAM_ARGS=`echo "$@"`
mvn exec:java -Dexec.mainClass="test.Main" -Dexec.args="$JAVA_PROGRAM_ARGS"
Then you are able to execute:
./run.sh arg1 arg2 arg3
Source: Stackoverflow.com