I attempted to implement my own version of a restartApplication method I found on the internet. All I added was the location of my javabin and the location of a jar file for it to relaunch. I also made the method static so I don't have to create an object to call it.
When I run my program, it runs fine up until the point it is supposed to restart. Instead of restarting, I get this error:
java.io.IOException: Cannot run program "null\bin\java": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java :1029)
at TreeChartUI.restartApplication(TreeChartUI.java:54 3)
at TreeChartUI.main(TreeChartUI.java:596)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:189)
at java.lang.ProcessImpl.start(ProcessImpl.java:133)
at java.lang.ProcessBuilder.start(ProcessBuilder.java :1021)
... 2 more
Here is my attempt at the restart method.
public static void restartApplication() { final String javaBin = System.getProperty("C:\\Program Files\\Java\\jdk1.7.0_05\\bin") + File.separator + "bin" + File.separator + "java"; final File currentJar = new File("C:\\Somefolder\\someJar.jar");//new File(UpdateReportElements.class.getProtectionDomain().getCodeSource().getLocation().toURI()); /* is it a jar file? */ if(!currentJar.getName().endsWith(".jar")) return; /* Build command: java -jar application.jar */ final ArrayList<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-jar"); command.add(currentJar.getPath()); final ProcessBuilder builder = new ProcessBuilder(command); try{ builder.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); }