我刚刚开始使用Eclipse RCP应用程序,它基本上只是所提供的“hello world”样本之一。
当应用程序启动时,我想查看我的命令行参数并根据它们启动一些服务。我可以在IApplication.start中获取命令行参数:
public Object start(IApplicationContext context) {
String[] argv = (String[])
context.getArguments().get(IApplicationContext.APPLICATION_ARGS)));
}
但是,如何获取BundleContext,以便注册服务?它似乎不在IApplicationContext中。
最佳答案
棘手的内部方式:
InternalPlatform.getDefault().getBundleContext()
能做到这。您将在this class中找到一个示例
public class ExportClassDigestApplication implements IApplication {
public Object start(IApplicationContext context) throws Exception {
context.applicationRunning();
List<ExtensionBean> extensionBeans = ImpCoreUtil.loadExtensionBeans("com.xab.core.containerlaunchers");
for (ExtensionBean bean : extensionBeans) {
ILauncher launcher = (ILauncher) bean.getInstance();
launcher.start();
}
ClassFilter classFilter = new ClassFilter() {
public boolean isClassAccepted(Class clz) {
return true;
}
};
PrintWriter writer = new PrintWriter( new File( "C:/classes.csv"));
Bundle[] bundles = InternalPlatform.getDefault().getBundleContext().getBundles();
Proper way: