1
我已經創建了一個eclipse應用程序和一個產品配置。在RCP應用程序中讀取程序參數?
在「啓動」選項卡上的產品配置中,可以指定「程序參數」和「虛擬機參數」。
是否可以從Application類訪問這些參數?目前,這個類看起來是這樣的:
public class Application implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
Map<?, ?> arguments = context.getArguments(); // this is empty!
// This actually does the trick but is a bit ugly - must be parsed
String[] strings = (String[]) context.getArguments()
.get("application.args");
Display display = PlatformUI.createDisplay();
try {
ApplicationWorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);
if (returnCode == PlatformUI.RETURN_RESTART) {
return IApplication.EXIT_RESTART;
} else {
return IApplication.EXIT_OK;
}
} finally {
display.dispose();
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.equinox.app.IApplication#stop()
*/
@Override
public void stop() {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null) {
return;
}
final Display display = workbench.getDisplay();
display.syncExec(new Runnable() {
@Override
public void run() {
if (!display.isDisposed()) {
workbench.close();
}
}
});
}
是否有更好的方法來提取應用ARGS比:
// This actually does the trick but is a bit ugly
String[] strings = (String[]) context.getArguments()
.get("application.args");