title: How to run a shell script from Java and have it continue running after JVM shutdown?
body: <p>I'm writing a plugin in order to restart a server application on Linux (though I'm testing on OSX). The way I'm doing this is using a shell script which commands the application to stop, and then oversees the death of the process, safely starting a new one when the time comes.</p>
  
  <p>My script works when I execute it manually from the command line. However, when I execute it from within the application, the shell process is killed along with the application.</p>
  
  <p>I've tried two different methods of running the process from Java:</p>
  
  <pre><code>String scriptArgs[] = {"sh", "restart.sh", "&amp;"};
  
      try {
          Runtime.getRuntime().exec(scriptArgs);
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ProcessBuilder processBuilder = new ProcessBuilder("sh", "restart.sh");
      try {
          processBuilder.directory(new File(System.getProperty("user.dir")));
          processBuilder.redirectErrorStream(false);
          processBuilder.start();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>Both of these methods gave the same result: the script was called, it successfully shut down the application, and then it died before it could continue. Is there any method to start a <em>completely</em> independent process from Java?</p>