How to programmatically restart the jar?

Can the jar executable restart itself? For example, after the user has made some choice, the program says "Restart the application?". and the user clicks "Yes", then the bank turns off and restarts.

+3
source share
2 answers

The need to restart the application is a sign of poor design.

I would definitely try to “reinitialize” the application (re-read configuration files, reconnect or ever), instead of forcing the user to terminate / launch the application (even if it was done automatically).

"" runner, - :

public class Runner {
    public static void main(String... args) {
        while (true) {
            try {
                new YourApplication().run();
                return;
            } catch (RestartException re) {
            }
        }
    }
}
+2

, Jar , Jar. .

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("java -jar locatio/of/the/jar");
System.exit(0);
+1

Source: https://habr.com/ru/post/1749405/


All Articles