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

前端 未结 5 1518
别跟我提以往
别跟我提以往 2021-01-11 22:44

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

相关标签:
5条回答
  • 2021-01-11 23:02

    You were on the right track with declarative services. Registering your services manually is a lot like hard work, and looking them up safely can be even more work, and tricky to get right. Another standard in this area to be aware of is Blueprint, although I certainly don't suggest you rewrite anything if you have DS metadata in place. Blueprint has slightly nicer characteristics in a very dynamic environment, and a richer configuration. (I'm a committer on one of the Blueprint implementations, Apache Aries.) With both Blueprint and DS the important thing is that something else is managing your services for you.

    This leaves us back with the issue of why your bundles aren't being started. I think there must be a clue in the fact that they do start in Felix. Have you fired up an equinox console and confirmed all your bundles are installed and resolved? ('ss' to list bundles.) Have you had a look in the config.ini file and confirmed your bundles are listed, and with an appropriate start level - or are you using the Equinox auto-start-everything else bundle?

    0 讨论(0)
  • 2021-01-11 23:05

    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.

    0 讨论(0)
  • 2021-01-11 23:20

    Sigh. You're the victim of a misguided strategy in Eclipse to prevent (dumb) programmers from extending the startup time. Instead of warning, they just decided not to start bundles at all. This is the opposite of what OSGi recommends :-( A bundle could only get activated (they basically voided start) when somebody loaded a class from it (this is what lazy activation is.)

    The by far best solution is to use Declarative Services. You can declare immediate services, which will be activated at startup, and you can declare lazy services, which get activated when used. The lazy are of course preferred (when you're not a dumb programmer) but certain use cases require immediate, like example a server that offers it services over the internet. You have to make sure in your config.ini that DS is started.

    0 讨论(0)
  • 2021-01-11 23:24

    MANIFEST.MF has this:

    Bundle-ActivationPolicy: lazy
    

    This could be also useful:

    http://wiki.eclipse.org/Lazy_Start_Bundles#Should_I_change_to_the_new_Bundle-ActivationPolicy_Header.3F

    However I would say I would try relying on OSGI activation as much as possible. If there is no other way of solving your problem, then the previous link might help.

    0 讨论(0)
  • 2021-01-11 23:25

    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.

    0 讨论(0)
提交回复
热议问题