I want to set environment variable in JAVA . For this , I have searched a lot in internet and got the following code
ProcessBuilder pb = new ProcessBuilder();
Map<String, String> 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<String, String> getenv = System.getenv();
Set<Entry<String,String>> entrySet = getenv.entrySet();
for (Entry<String, String> entry : entrySet) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
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.