开发者

Problem with restart standalone RCp application

开发者 https://www.devze.com 2022-12-08 01:03 出处:网络
I have problem with restarting RCP application. When I run under Eclipse everything is ok, but when I create standalone application method restart jus开发者_JAVA技巧t close the applications. I use nex

I have problem with restarting RCP application. When I run under Eclipse everything is ok, but when I create standalone application method restart jus开发者_JAVA技巧t close the applications. I use next code: IWorkbench workbench = PlatformUI.getWorkbench(); workbench.restart(); Is anybody know how to solve this.

THANKS


This thread is interesting in that regard (it explains why it works when the RCP is run from eclipse, and not when running standalone)

If the workbench is restarted, e.g. via IWorkbench.restart(), that causes PlatformUI.createAndRunWorkbench(...) to return control to the application (the IPlatformRunnable implementation for the application extension) with a return code of PlatformUI.RETURN_RESTART (value is 1).

The application then must map this to an app return code of IPlatformRunnable.EXIT_RESTART (value is 23).

This then becomes the exit code of the Java VM (i.e System.exit(code)).
The eclipse.exe executable detects this special code, and relaunches the Java VM using the same command line arguments as the first time.

If you're not using eclipse.exe but are launching the java VM directly yourself, it won't restart automatically. You'll need to handle the exit code yourself.

So a code like that in your RCP will need to be amanged by some kind of launcher in order to interpret (and restart the rcp application if needed) the exist code.
(a bit like in this remote RCP management wiki page)

WorkbenchAdvisor workbenchAdvisor = new CoreAppWorkbenchAdvisor();
Display display = PlatformUI.createDisplay();
try {
  int returnCode = PlatformUI.createAndRunWorkbench(display, workbenchAdvisor);
  if (returnCode == PlatformUI.RETURN_RESTART)
    return IPlatformRunnable.EXIT_RESTART;
  else
    return IPlatformRunnable.EXIT_OK;
  }
  finally {
    display.dispose();
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号