Reputation: 2642
I can get environment variable like this
final String value = System.getenv("PE_CONF_PWD");
But how can I change environment variables ??
Upvotes: 2
Views: 862
Reputation: 1145
The Java System class doesn't let you set environment variables for you Operating system directly. You can retrieve them using getenv() but there is no equivalent setenv() method.
When you start up the JVM, it copies your os's environment into its own Map of Strings. The actual container it uses is an unmodifiable map, probably to be extra safe.
So in a running Java application you have 2 environments: the JVM copy that you can read via System.getenv() and the underlying environment that lives in the C library.
You should be able to change the JVM's copy using Reflection.
Upvotes: 2