Archive
Eclipse Extension Points and Extensions without OSGi
Eclipse provides the concept of "extension points" and "extensions" to facilitate that functionality can be contributed to plugins by other plugins.. Lars Vogel explained very good this mechanism in her Eclipse Extension Points and Extensions – Tutorial.
In this tutorial, you can find 2 Plug-ins :
- de.vogella.extensionpoint.definition Plug-in (Eclipse RCP) which :
- defines the Extension Point de.vogella.extensionpoint.definition.greeter declared in the plugin.xml :
<plugin> <extension-point id="de.vogella.extensionpoint.greeters" name="Greeters" schema="schema/de.vogella.extensionpoint.greeters.exsd"/> </plugin>
to get instance of de.vogella.extensionpoint.definition.IGreeter.
- reading the registered extension (registered by the second Plug-in de.vogella.extensionpoint.contribution) to retrieve de.vogella.extensionpoint.definition.IGreeter instance :
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(IGREETER_ID);
- defines the Extension Point de.vogella.extensionpoint.definition.greeter declared in the plugin.xml :
- de.vogella.extensionpoint.contribution which provides the Extension to register an instance of de.vogella.extensionpoint.contribution.GreeterGerman declared in the plugin.xml :
<plugin> <extension point="de.vogella.extensionpoint.definition.greeter"> <client class="de.vogella.extensionpoint.contribution.GreeterGerman"> </client> </extension> </plugin>
This sample works well in OSGi context, but is it possible to use Extension Point/Extension mechanism without OSGi? The answer is yes! The Plug-in org.eclipse.equinox.registry which manages the Extension Point/Extension mechanism works only with OSGi context, but the Extension Point/Extension API was thought to be extensible and not linked to OSGi.
The bug 322189 provides the Plug-in org.eclipse.equinox.nonosgi.registry which implements Extension Point without OSGi (but with OSGi too). In this article I will explain how use org.eclipse.equinox.nonosgi.registry by modifying (a little) the Lars tutorial to launch de.vogella.extensionpoint.definition.Application with Java main (without OSGi context) :
public static void main(String[] args) {
IApplication application = new Application();
try {
application.start(null);
} catch (Exception e) {
e.printStackTrace();
}
}