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.
-
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– Oliver Charlesworth2012-03-20 18:01:15 +00:00Commented Mar 20, 2012 at 18:01
-
1possible duplicate of How do I set environment variables from Java?Edward Thomson– Edward Thomson2012-03-20 18:09:22 +00:00Commented Mar 20, 2012 at 18:09
Add a comment
|
4 Answers
I suspect this is not possible. System.getenv() is an unmodifiable map, meaning you can't modify elements in it.
1 Comment
Zack Macomber
He can use ProcessBuilder to set env variables - see the link I put in my post and also the "possible duplicate" comment
Have you try ?
System.setProperty("KEY", "VALUE");
2 Comments
Edward Thomson
That's a Java system property. It's not an environment variable.
remi dupuis
My bad, I wasn't careful enough.