My question is quite basic and I am a bit surprised I could not easily find an answer by googling or from maven-exec-plugin documentation.
I need to execute my java program in my maven project, providing both jvm arguments, system properties, and the program arguments from the command line at the invocation time.
I expect maven to provide the classpass and also the main class from pom.xml, so that I don't have to write them when I invoke my program.
As the jvm arguments, the system properties, and the program arguments differ from invocation to invocation, I can't specify them in my pom.xml.
I want to do something like this:
Invocation 1:
mvn exec:whatever -Dexec.systemProperties='p1=v1' -Dexec.jvmArguments='-XX:NewRatio=1' -Dexec.args='a b c'
Invocation 2:
mvn exec:whatever -Dexec.systemProperties='p2=v2 p3=v3' -Dexec.jvmArguments='-Xmx=10g -XX:PrintGCDetails' -Dexec.args='f h g'
(The 'exec:whatever', '-Dexec.systemProperties' etc. are just placeholders to clarify my intention and can be replaced by any other goals and arguments).
Partial answer:
I know that I can use exec:java
goal and provide both program arguments and system properties like this:
mvn -Dp1=v1 -Dp2=v2 exec:java -exec:args="a b c"
This works fine, as exec:java
does not fork a new process so system properties provided to maven are accessible by my program as well. But then I don't know how to pass the jvm flags, like '-XX:PringGCDetails', from the command line.
Of course, I always have an option to create a fat jar and then use regular java
command to invoke it.
Yet I'd like to know whether there is a way to tweak maven-exec-plugin or similar to invoke my program without creating a fat jar, and still allow me to provide system properties, jvm, and program arguments at the time of the invocation.