Is it possible to set an environment variable at runtime from Java?

前端 未结 6 1765
旧巷少年郎
旧巷少年郎 2020-11-27 05:02

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

6条回答
  •  时光取名叫无心
    2020-11-27 05:43

    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.

提交回复
热议问题