4

Is there a way to set an environment var on mvn exec:java from the commandline?

Something like:

mvn exec:java --Dexec.env="env1=foobar"
mtyson
  • 8,196
  • 16
  • 66
  • 106
  • 1
    `exec:java` doesn't fork a new VM, so no, not possible. But `exec:exec` does fork a new VM, so [yes](http://www.mojohaus.org/exec-maven-plugin/exec-mojo.html#environmentVariables). – Tunaki Nov 01 '16 at 00:58
  • 1
    On *NIX, you should be able to do `env1=foobar; mvn exec:java` – Elliott Frisch Nov 01 '16 at 01:03
  • 1
    Have a look if one of those does work: https://stackoverflow.com/questions/3708846/how-to-pass-systemproperties-when-invoking-execjava-plugin-in-maven – dudel Nov 01 '16 at 10:22
  • 1
    @ElliottFrisch It is not enough! The environment variable must be exported, to make it visible for the child processes. Thus, the correct syntax is: `export ENV1=foobar; mvn exec:java` or `ENV1=foobar mvn exec:java`. You either need also an `export`, or you have to leave out the "`;`". – peterh Jun 08 '18 at 14:48

0 Answers0