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.

2
  • Please clarify: You want to set environment variables to hardcoded values from within the program that's then going to read those environment variables? Commented Mar 20, 2012 at 18:01
  • 1
    possible duplicate of How do I set environment variables from Java? Commented Mar 20, 2012 at 18:09

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

He can use ProcessBuilder to set env variables - see the link I put in my post and also the "possible duplicate" comment
0

Environment Variables

And for setting environment variables, ProcessBuilder

Comments

-1

Have you try ?

System.setProperty("KEY", "VALUE");

2 Comments

That's a Java system property. It's not an environment variable.
My bad, I wasn't careful enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.