How to pass enviornment variables to jar file?

10,496
ENV_VAR=some-value java -jar path/to/theJar.jar

You can then access that in Java via System.getEnv('ENV_VAR')

In java you can also do system properties

java -Dsome.system.prop=some-value -jar path/to/theJar.jar

you can then access the system props in code via System.getProperty('some.system.prop')

Share:
10,496
Shwetali
Author by

Shwetali

Updated on June 04, 2022

Comments

  • Shwetali
    Shwetali almost 2 years

    I want to set run configuration option : Environment variable while running JAR and run it using java code. How to set environment option while running jar through java code?

    • zbarker
      zbarker almost 5 years
      Clarified title.