Problem with restart standalone RCp application
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 causesPlatformUI.createAndRunWorkbench(...)
to return control to the application (theIPlatformRunnable
implementation for the application extension) with a return code ofPlatformUI.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)
).
Theeclipse.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();
}
}
精彩评论