增加重启程序的方法

This commit is contained in:
许轲 2023-09-30 01:34:25 +08:00
parent 1b2c08473b
commit 34a42310ab

View File

@ -0,0 +1,30 @@
package org.jcnc.jnotepad.app.util;
import org.jcnc.jnotepad.util.LogUtil;
import org.slf4j.Logger;
import java.io.IOException;
/**
* @author luke
*/
public class ApplicationRestarter {
public static void restart() {
try {
// 获取当前Java应用程序的命令
String javaCommand = System.getProperty("java.home") + "/bin/java";
String mainClass = ApplicationRestarter.class.getName();
// 构建新进程来重新启动应用程序
ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", System.getProperty("java.class.path"), mainClass);
builder.start();
// 关闭当前应用程序
System.exit(0);
} catch (IOException e) {
LogUtil.getLogger("正在重启当前应用程序".getClass());
}
}
}