Java 对于Eclipse片段项目是否有一个与BundleActivator等效的工具?

Java 对于Eclipse片段项目是否有一个与BundleActivator等效的工具?,java,eclipse,eclipse-plugin,eclipse-fragment,Java,Eclipse,Eclipse Plugin,Eclipse Fragment,我正在构建一个Eclipse插件,它在常规插件项目中提供了一组核心特性。我通过片段项目提供的可选特性。但我需要这些片段在启动时向主插件注册 我不能在片段项目中使用捆绑激活器。所以我想知道是否有其他机制来声明一个入口点或一些我可以钩住的回调 如果除了将片段项目转换为常规插件项目之外没有其他选择,那么我需要注意的是有什么缺点吗 这是我根据公认的答案使用的解决方案: final IExtensionRegistry registry = Platform.getExtensionRegistry();

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

我不能在片段项目中使用捆绑激活器。所以我想知道是否有其他机制来声明一个入口点或一些我可以钩住的回调

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

这是我根据公认的答案使用的解决方案:

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)
            {
            }
        }
    }
}
final IExtensionRegistry registry=Platform.getExtensionRegistry();
final IExtensionPoint extensionPoint=registry.getExtensionPoint(“myextensionid”);
final IExtension[]extensions=extensionPoint.getExtensions();
对于(int j=0;j
您可以定义扩展点并通过扩展查找/调用片段类

    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();
            }
        }
    }
}

编辑:

要使用这种方法,我必须转换 我的片段投影到插件 项目-Bmatthews 68

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

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
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
    <extension-point id="myextension" name="myextension"
        schema="schema/myextension.exsd" />
</plugin>
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"
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<fragment>
   <extension
         point="myplugin.myextension">
      <myextensionFactory
            class="myfragment.MyExtension1">
      </myextensionFactory>
   </extension>
</fragment>
plugin.xml

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
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
    <extension-point id="myextension" name="myextension"
        schema="schema/myextension.exsd" />
</plugin>
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"
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<fragment>
   <extension
         point="myplugin.myextension">
      <myextensionFactory
            class="myfragment.MyExtension1">
      </myextensionFactory>
   </extension>
</fragment>
fragment.xml

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
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
    <extension-point id="myextension" name="myextension"
        schema="schema/myextension.exsd" />
</plugin>
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"
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<fragment>
   <extension
         point="myplugin.myextension">
      <myextensionFactory
            class="myfragment.MyExtension1">
      </myextensionFactory>
   </extension>
</fragment>


这些项目是使用Eclipse3.3.1.1生成的。

通过您的回复,我第一次尝试就能够在插件中使用此功能。谢谢你的帮助。这个问题应该作为如何使用stackoverflow的一个例子。谢谢