You can add the desired variables directly into ProcessBuilder.environment()
map.
The code below should work:
import java.util.Map;
import java.util.Set;
class helloworld {
public static void main(String[] args) {
ProcessBuilder pb = new ProcessBuilder("/bin/sh"); // or any other program you want to run
Map envMap = pb.environment();
envMap.put("MY_ENV_VAR", "1");
Set keys = envMap.keySet();
for(String key:keys){
System.out.println(key+" ==> "+envMap.get(key));
}
}
}