How to auto-start/eager start OSGi services on Eclipse platform

Rick-Rainer Ludwig picture Rick-Rainer Ludwig · Mar 12, 2012 · Viewed 9.3k times · Source

I develop an Eclipse RCP application which makes heavy use of OSGi bundles which provide services for later use. The use case requires the bundles to register their services (e.g. import filters) to be used later on in different situations. The OSGi bundles are build with maven-bundle-plugin.

How can I tell Equinox to start the OSGi bundles automatically? The normal approach via Activator is not working. Only the lazy mode is working, but I can not touch classes within unknown bundles. I read the OSGi specification and the opposite to lazy load, eager load, is not provided. Is there another chance to mark the bundle for an auto load?

Within Eclipse I have a chance to set Auto-Start to true, but what do I do within a distribution build by Maven and Tycho?

Declarative services are not working due to the issue of a not loaded org.eclipse.equinox.ds. Can I get it started somehow instead of an Activator? This would be a solution, too, but I do not know how to build the distribution or what to set as configuration.

What are best practices here? Are there any other possibilities? The documentation on OSGi bundles on Eclipse platform is a little thin.

Answer

Nick Wilson picture Nick Wilson · Mar 13, 2012

You can use the "org.eclipse.ui.startup" extension point in your plugin. This allows you to specify an IStartup class that will be called when the Eclipse UI starts up. As long as this is a class in your bundle then your bundle will be started.

It will mean including a plugin.xml file, and this would be specifically an Eclipse plugin rather than a standard OSGi bundle, but you could then use this plugin to activate any of your standard OSGi bundles.