Having IStartup.earlyStartup() run without BundleActivator.start() being called although the Activator was properly set. Why?

空扰寡人 提交于 2019-12-24 19:12:29

问题


To put it bluntly: is there any explanation for having an Eclipse plugin running its IStartup.earlyStartup() method but not BundleActivator.start() other than having a faulty(or no) Activator set on the Manifest file?

I quadruple checked and I'm positive I didn't incorrectly set the Activator in the Manifest, so I'm finding this behavior rather bizarre.

When running this plugin as part of a tool we're developing, the Activator is indeed ran although for some reason earlyStartup() doesn't, but when I try to run the same plugin through Eclipse, just the opposite happens.

From my understanding BundleActivator.start() always runs, so I'm finding this behavior rather intriguing. I'm pretty positive I've correctly set the Activator as if I try to type some other thing Eclipse complains "the given class is not on the class path".

Any clues on the matter would be greatly appreciated.


回答1:


Check the state of the bundle... if it is RESOLVED (as I believe it will be) then you have your answer. OSGi only calls the BundleActivator.start() method when the bundle is actually started! Eclipse unfortunately does not start the bundle before it calls the IStartup extension.

You can force OSGi to start the bundle by setting Bundle-ActivationPolicy: lazy in your MANIFEST.MF. This is a flag to both Eclipse and OSGi which results in the bundle automatically starting when the first class is loaded from the bundle. Probably the class that is loaded will be your IStartup implementation.

However IMHO Bundle-ActivationPolicy unnecessarily complicates the OSGi lifecycle and I hate it...



来源:https://stackoverflow.com/questions/17456359/having-istartup-earlystartup-run-without-bundleactivator-start-being-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!