From 34a42310ab5f79cccc8c4089f387ff7e81b253df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E8=BD=B2?= Date: Sat, 30 Sep 2023 01:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E5=90=AF=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/util/ApplicationRestarter.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java diff --git a/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java b/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java new file mode 100644 index 0000000..5aa891d --- /dev/null +++ b/src/main/java/org/jcnc/jnotepad/app/util/ApplicationRestarter.java @@ -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()); + + } + } +}