To run a java class from maven we can use org.codehaus.mojo:exec-maven-plugin. This offers two goals: exec & java. The exec goal runs the program in a seperate process. Below is the usage of these goals:
args is treated as single string
arguments is treated as an array of strings
mvn exec:java -Dexec.mainClass=org.junit.runner.JUnitCore -Dexec.args="MyTest"
mvn exec:java -Dexec.mainClass=org.junit.runner.JUnitCore -Dexec.arguments="MyTest"
mvn exec:exec -Dexec.executable=java -Dexec.args="-cp %classpath org.junit.runner.JUnitCore MyTest"
I was trying to run a JUnit test case as a class instead of using with surefire plugin as a unit test. Also note the classpath setting for exec goal, % is only at the beginning. This would be replaced by the project build classpath.