Is it possible to set an environment variable at runtime from a Java application? In Java 1.5 java.lang.System class there is the getenv() method, I would only need a setenv
I don't think so, at least not purely in Java, but why do you need to do this? In Java it's preferable to use properties via System.getProperties()
, which you can modify.
If you really must, I'm sure you could wrap the C setenv
function in a JNI call - in fact, I wouldn't be surprised if someone has done so already. I don't know the details of the code, though.