Maven exec plugin lets you run the main method of a Java class in your project, with the project dependencies automatically included in the classpath.
This article show you a way of using the maven exec plugin to run java, with code examples.
Complile the code
Since you are not running your code in a maven phase, you first need to compile the code. Remember exec:java does not automatically compile your code, you need to do that first.
Running from Command line
Once your code is compiled, the following command runs your class
1) Without arguments
mvn exec:java -Dexec.mainClass="com.pengyifan.FooMain"
2) With arguments:
mvn exec:java -Dexec.mainClass="com.pengyifan.FooMain" / -Dexec.args="arg0 arg1 arg2"
When Maven starts-up command, it reads two files
So we can setup maven settings there.
For example, to switch java to version 8, we can add the following to
To setup the heap size of JVM, add