是否有与Eclipse片段项目相同的BundleActivator?

我正在构建一个Eclipse插件,它在常规插件项目中提供了一组核心function。 我通过片段项目提供的可选function。 但我需要片段在启动时使用主插件注册自己。

我不能在片段项目中拥有Bundle-Activator。 所以我想知道是否有一些替代机制来声明我可以挂钩的入口点或某些回调?

如果除了将片段项目转换为常规插件项目之外没有其他选择,那么我需要注意一个缺点吗?

这是我根据接受的答案使用的解决方案:

final IExtensionRegistry registry = Platform.getExtensionRegistry(); final IExtensionPoint extensionPoint = registry.getExtensionPoint("myextensionid"); final IExtension[] extensions = extensionPoint.getExtensions(); for (int j = 0; j < extensions.length; ++j) { final IConfigurationElement[] points = extensions[j].getConfigurationElements(); for (int i = 0; i < points.length; ++i) { if ("myelementname".equals(points[i].getName())) { try { final Object objImpl= points[i].createExecutableExtension("class"); objImplList.add(provider); } catch (CoreException e) { } } } } 

您可以定义扩展点并通过扩展查找/调用您的片段类。

  IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry .getExtensionPoint("myplugin.myextension"); IConfigurationElement points[] = extensionPoint .getConfigurationElements(); for (IConfigurationElement point : points) { if ("myextensionFactory".equals(point.getName())) { Object impl = point.createExecutableExtension("class"); if (impl instanceof IMyExtension) { ((IMyExtension) impl).foo(); } } } } 

编辑:

要使用这种方法,我必须将我的片段项目转换为插件项目。 – bmatthews68

你不应该这样做。 例如,在我的测试代码中,我在主机插件中有以下文件:

META-INF / MANIFEST.MF

 Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Myplugin Plug-in Bundle-SymbolicName: myplugin;singleton:=true Bundle-Version: 1.0.0 Bundle-Activator: myplugin.Activator Require-Bundle: org.eclipse.core.runtime Eclipse-LazyStart: true Export-Package: myplugin 

plugin.xml

      

该片段包含以下文件:

META-INF / MANIFEST.MF

 Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Myfragment Fragment Bundle-SymbolicName: myfragment;singleton:=true Bundle-Version: 1.0.0 Fragment-Host: myplugin;bundle-version="1.0.0" 

fragment.xml

         

这些项目是使用Eclipse 3.3.1.1生成的。