问题
I have a plugin that forces a restart of Eclipse by using:
Workbench.getInstance().restart();
However, I need this restart to include a new environment variable:
eclipse.refreshBundles=true
Is there any way to add such an environment variable for this next restart of Eclipse only?
回答1:
Eclipse has 2 modes for restarting: "restart" using the previous command line, or "relaunch" using a new command line. The launcher itself will remember the previous command line, so in order to add a new system property, you will need to do the relaunch.
The restart/relaunch is part of the IApplication API, the Workbench.restart() will cause the IDEApplication to return relaunch if you set the system property eclipse.exitcode=24
.
For the relaunch, you need to put the new command line in the eclipse.exitdata
system property. You will need to reconstruct the command line using the eclipse.commands
and eclipse.vmargs
system properties, and add a -Declipse.refreshBundles=true
vm argument. For an example of this, take a look at OpenWorkspaceAction
in org.eclipse.ui.ide which uses the relaunch to switch workspaces.
Note that in the restarted eclipse, the eclipse.refreshBundles will be part of the command line, and will remain there for further restarts unless you modify the system properties. It will be gone if you exit fully and start again.
来源:https://stackoverflow.com/questions/1539601/adding-extra-system-properties-to-an-eclipse-programmatic-restart