I want to recreate java -jar [jar] &>logfile &
in java via the ProcessBuilder.
Here's my current code:
File outFile = new File(".."); // logfile
ProcessBuilder builder = new ProcessBuilder(args); // args = ["java", "-jar", "[jar]"]
builder.redirectError(outFile);
builder.redirectOutput(outFile);
Process process = builder.start();
The said jar is a web server and is supposed to run forever. But when I exit the java process that spawned the server it is also terminated.
My question now is: How do I tell the ProcessBuilder to execute the command in a background thread that doesn't terminate when the caller exits?
Prepending the args with nohup
has not changed this behavior, using:
args = ["nohup", "java", "-jar", "[jar]"]
I've also tried
args = ["nohup", "java", "-jar", "[jar]", "&"]
Both of these do not work, neither on windows or linux