I start a JAR file from my java swing file using Process proc Runtime.getruntime.exec();
and I need to shut it down so it works on all operating systems.
I've tried proc.detroy();
but that doesn't let it fully shut down and will cause problems with the program.
What do I need to do to get it to shut down safely on all operating systems?
I assume I will need to check what OS is being used and handle each one separately but what should be done to get it to safely shut down on each one?
Here is the StartStop.java code:
public class StartStop {
static Process proc = null;
public void program() {
new Thread() {
public void run() {
try {
proc = Runtime.getRuntime().exec("java -jar DEDServer_release.jar");
String res = org.apache.commons.io.IOUtils.toString(new BufferedReader(new InputStreamReader(proc.getErrorStream())));
if(res.contains("Error")){
JOptionPane.showMessageDialog(null, "Failed to start DEDServer. Make sure that this file is in the same directory as DEDServer_release.jar");
}
}catch (IOException e) {
JOptionPane.showMessageDialog(null, "Failed to start DEDServer. Make sure that this file is in the same directory as DEDServer_release.jar");
}
}
}.start();
}
}
Thank you for your help.