0
我想每一個應用程序從這個主要方法在調試模式下重新啓動程序
public static void main(String[] args) throws Exception
{
boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
JOptionPane.showMessageDialog(null, isDebug);
Utility.restartApplication();
}
的JOptionPane的啓動時使用此代碼
public static final String SUN_JAVA_COMMAND = "sun.java.command";
public static void restartApplication() throws IOException
{
try
{
String java = System.getProperty("java.home") + "/bin/java";
final StringBuffer cmd = new StringBuffer("\"" + java + "\" ");
String[] mainCommand = System.getProperty(SUN_JAVA_COMMAND).split(" ");
if (mainCommand[0].endsWith(".jar"))
{
cmd.append("-jar " + new File(mainCommand[0]).getPath());
}
else
{
cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]);
}
cmd.append("");
for (int i = 1; i < mainCommand.length; i++)
{
cmd.append(" ");
cmd.append(mainCommand[i]);
}
cmd.append(" -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000");
Runtime.getRuntime().exec(cmd.toString());
System.exit(0);
}
catch (Exception e)
{
throw new IOException("Error while trying to restart the application", e);
}
}
但是重新啓動在調試模式下的Java程序總是顯示該消息錯誤爲什麼不會這個工作
isDebug中的問題或與重新啓動應用程序;我認爲問題是重啓。
重新啓動似乎沒有工作 – Popgalop
嗯,上次我嘗試這是十年前,我仍然感到痛苦。編寫一個漂亮的批處理文件/ shell腳本,並調試它,直到調試器啓動,然後創建Java代碼以模仿批處理文件/ shell腳本, –