Is there a BundleActivator equivalent for Eclipse fragment projects?

I am creating an Eclipse plug-in that provides a set of basic functions in a regular plug-in project. Additional features that I provide through fragment projects. But I need the fragments to register in the main plug-in at startup.

I cannot have a Bundle-Activator in a fragment project. So I'm wondering if there is some alternative mechanism to declare an entry point or some kind of callback that I can connect?

And if there is no alternative besides converting the fragment project into a regular plug-in project, is there a flaw that I need to know about?

This is the solution I used based on the accepted answer:

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) { } } } } 
+3
java eclipse eclipse-plugin eclipse-fragment
source share
1 answer

You can define an extension point and search / call fragment classes through extensions.

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

EDIT:

To use this approach, I need to convert my fragment projects to plugin projects. - bmatthews68

You do not need. For example, in my test code, I have the following files in the host plugin:

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

 <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> <extension-point id="myextension" name="myextension" schema="schema/myextension.exsd" /> </plugin> 

The snippet contains these files:

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

 <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <fragment> <extension point="myplugin.myextension"> <myextensionFactory class="myfragment.MyExtension1"> </myextensionFactory> </extension> </fragment> 

These projects were created using Eclipse 3.3.1.1.

+5
source share

All Articles