Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 469
Rick-Rainer Ludwig Avatar asked Mar 12 '12 21:03

Rick-Rainer Ludwig


2 Answers

You can add this to your .product file:

<configurations>
    <plugin id="my.plugin.id" autoStart="true" startLevel="4" />
</configurations>

Alternatively, open the .product file in Eclipse and go to the Configuration tab, and add the plugin with the desired start level there.

like image 179
Chin Avatar answered Nov 02 '22 01:11

Chin


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.

like image 33
Nick Wilson Avatar answered Nov 02 '22 00:11

Nick Wilson