devoured elysium
devoured elysium

Reputation: 105067

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

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.

Upvotes: 0

Views: 587

Answers (1)

Neil Bartlett
Neil Bartlett

Reputation: 23948

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...

Upvotes: 2

Related Questions