增加重启程序的方法
This commit is contained in:
parent
1b2c08473b
commit
34a42310ab
@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user