1

I use terminal command "java -jar secondApp.jar" inside my java file to start a secondApp.jar.
I need secondApp.jar to run even if first app is killed.
This scenario works perfectly in windows environment. But when I test this in linux environment(Ubuntu 16.04) it seems that killing the first process kills the both processes.
This is the code I use to start the second app.

String command = "java -jar secondApp.jar"
Process process = Runtime.getRuntime().exec(command);

What am I doing wrong?

Lasitha Yapa
  • 4,309
  • 8
  • 38
  • 57

1 Answers1

0

Prepare a batch file and a linux script file with the desired java command, then try this:

    if (SystemUtils.IS_OS_WINDOWS) {
        // run batch file
        String batchFullPath = new File("C:\\myBatchFile.bat").getAbsolutePath();
        Runtime.getRuntime().exec("cmd /C start " + batchFullPath);
    } else if (SystemUtils.IS_OS_LINUX) {
        // run linux script
        String scriptFullPath = new File("~/myScriptFile.sh").getAbsolutePath();
        File workingDir = new File("~");
        Runtime.getRuntime().exec("/usr/bin/xterm " + scriptFullPath, null, workingDir);
    } else {
        throw new RuntimeException("Unsupported Operating System");
    }

(Using xterm as it is fairly safe to assume every Linux machine has it installed)

Yoav Gur
  • 1,366
  • 9
  • 15