Reputation: 1643
I need to somehow get command line arguments of a running Eclipse 4 application. I'm working on a small application based on the Eclipse 4 RCP, but I thing, this problem is more common. I'm unable to find out, how to get from code of a product respectively of a plug-in the command line argumnets, the application have been executed with.
I need to use a custom command line parameter to pass on information to my code. Do anybody know a hint?
Upvotes: 3
Views: 4171
Reputation: 1240
Since E4 is using Equinox as runtime you can use the Platform class to get the application arguments.
Platform.getApplicationArgs()
See Javadoc: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Findex.html
Upvotes: 5
Reputation: 1643
I've got it. It is not so intuitive, but it works for me. There is an instance implementing the IApplicationContext
interface. (The interface depends on the org.eclipse.equinox.app
.) The instance is reachable by the injection mechanism. The method getArguments()
returns a map. But it does not return a map of some command line parameters and their values. It returns some map, where it is under the key "application.args"
stored an array. Exampli gratia:
@PostConstruct
public void createControls(Composite parent, HtmlEditorService editorService, IApplicationContext iac) {
System.out.println(iac.getArguments().get("application.args").getClass().getCanonicalName());
...
}
Then it prints out java.lang.String[]
. However the array contains just my custom arguments instead all arguments. Fortunately it does not matter for me. I need to get my custom arguments only.
Additional hint for a plug-in activator
public class Aktivator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
ServiceReference<?> ser = context.getServiceReference(IApplicationContext.class);
IApplicationContext iac = (IApplicationContext)context.getService(ser);
System.out.println(iac.getArguments().get("application.args").getClass().getCanonicalName());
}
@Override
public void stop(BundleContext context) throws Exception {
}
}
Upvotes: 4