title: How to set the system variables using java program
body: <p>I want to set environment variable in JAVA . For this , I have searched a lot in internet and got the following code </p>
  
  <pre><code>ProcessBuilder pb = new ProcessBuilder();
  Map&lt;String, String&gt; env = pb.environment();
  env.put("DS_HOME", "C:\\MyFile\\jboss-eap-6.4\\modules\\com\\mycom\\library\\d_home");
  env.put("CS_HOME", "C:\\MyFile\\jboss-eap-6.4\\modules\\com\\mycom\\library\\c_home");
  pb.command("cmd.exe", "/c", "echo", "%DS_HOME%");
  pb.command("cmd.exe", "/c", "echo", "%CS_HOME%");
  try {
      pb.inheritIO().start();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  Map&lt;String, String&gt; getenv = System.getenv();
  Set&lt;Entry&lt;String,String&gt;&gt; entrySet = getenv.entrySet();
  for (Entry&lt;String, String&gt; entry : entrySet) {
      System.out.println(entry.getKey() + " " + entry.getValue());
  }
  </code></pre>
  
  <p>After Executing this code, i am not getting the custom variables which i have set using ProcessBuilder. Please help me out to solve this. I want to execute a service which needs some environments variables and to i am trying to set the system varibales using java code.</p>