tags:

views:

161

answers:

2

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

THANKS

+2  A: 

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();
  }
}
VonC
A: 

Thanks you very much for the information. It helps for solving the problem.

Nena

related questions