I'm running on Ubuntu.
I have Java a program being started from command line using java -jar myTopJar.jar
.
The myTopJar.jar should do something and than , run a second jar and terminate (the myTopJar.jar
should terminate and let the second jar run).
In order to run a jar and disowning it (I mean from command line) I used to run this command: java -jar mySecondJar.jar & disown
.
I expected the same behaviour when I run the command from Java utility that I'm using :
import org.apache.commons.exec.*;
public static int execCommand () throws ExecuteException, IOException, InterruptedException {
logger.debug("About to execute command: ", command);
CommandLine commandLine = CommandLine.parse("java -jar mySecondJar.jar & disown");
DefaultExecutor executor = new DefaultExecutor();
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
executor.execute(commandLine, resultHandler);
return 0;
}
I'm using Apache's commons-exec-1.2.jar
Just to make the flow clear:
- I'm running the myToJar.jar from Linux command line
- The last line in the
main()
method ofmyTopJar.jar
should call the aboveexecCommand()
method and exit (expecting themySecondJar.jar
to continue running).
The result is that myTopJar.jar
termination, terminates the mySecondJar.jar
process as well.
Can someone please assist here?