0

If I had a java application that needed specific environment variables to be set, but I cannot place them inside the bash.rc or bash_profile, nor can I place them in /etc/profile.d is it possible to have them set within the Java process? Or do these need to be set before the java process is run? Also manually setting them each time is not an option because I want them to be transparent to the user.

Matthew Hoggan
  • 7,402
  • 16
  • 75
  • 140
  • Please clarify: You want to set environment variables to hardcoded values from within the program that's then going to read those environment variables? – Oliver Charlesworth Mar 20 '12 at 18:01
  • 1
    possible duplicate of [How do I set environment variables from Java?](http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java) – Edward Thomson Mar 20 '12 at 18:09

4 Answers4

4

Start the java process from a shell script. The script would first define and export the environment variables.

Ben Rowland
  • 361
  • 1
  • 5
0

Environment Variables

And for setting environment variables, ProcessBuilder

Zack Macomber
  • 6,682
  • 14
  • 57
  • 104
0

I suspect this is not possible. System.getenv() is an unmodifiable map, meaning you can't modify elements in it.

Adam
  • 35,919
  • 9
  • 100
  • 137
  • He can use ProcessBuilder to set env variables - see the link I put in my post and also the "possible duplicate" comment – Zack Macomber Mar 20 '12 at 18:18
-1

Have you try ?

System.setProperty("KEY", "VALUE");
remi dupuis
  • 119
  • 3