title: How do I set environment variables from Java?
body: <p>How do I set environment variables from Java?  I see that I can do this for subprocesses using <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html" rel="noreferrer"><code>ProcessBuilder</code></a>. I have several subprocesses to start, though, so I'd rather modify the current process's environment and let the subprocesses inherit it.</p>
  
  <p>There's a <code>System.getenv(String)</code> for getting a single environment variable. I can also get a <code>Map</code> of the complete set of environment variables with <code>System.getenv()</code>. But, calling <code>put()</code> on that <code>Map</code> throws an <code>UnsupportedOperationException</code> -- apparently they mean for the environment to be read only. And, there's no <code>System.setenv()</code>.</p>
  
  <p>So, is there any way to set environment variables in the currently running process?  If so, how?  If not, what's the rationale?  (Is it because this is Java and therefore I shouldn't be doing evil nonportable obsolete things like touching my environment?)  And if not, any good suggestions for managing the environment variable changes that I'm going to need to be feeding to several subprocesses?</p>