Restarting a Java AWT Application
Restarting a Java AWT application involves invoking an external process to re-launch the application. While there is no direct equivalent to Application.Restart() in Java, the following method can be utilized to achieve the same effect:
public void restartApplication() { String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; File currentJar = new File(MyClassInTheJar.class.getProtectionDomain().getCodeSource().getLocation().toURI()); if (!currentJar.getName().endsWith(".jar")) { return; } ArrayList<String> command = new ArrayList<>(); command.add(javaBin); command.add("-jar"); command.add(currentJar.getPath()); ProcessBuilder builder = new ProcessBuilder(command); builder.start(); System.exit(0); }
This method performs the following steps:
The above is the detailed content of How to Restart a Java AWT Application?. For more information, please follow other related articles on the PHP Chinese website!