Search code examples
eclipseeclipse-rcprcposgi-bundlelazy-initialization

Eclipse RCP: bundle activation upon resource request


The Eclipse-LazyStart header is used to specify if a bundle should be started before the first class or resource is accessed from that bundle

Taken from the official Eclipse documentation.
It can be inferred from this sentence that if one specifies Eclipse-LazyStart (or Bundle-ActivationPolicy: lazy in Equinox 3.4+) the bundle will be activated upon first class or resource request.

Originally I meant to ask how one may add a resource file to activation exception list, as according to the documentation the exception list consists of class packages only:
Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.foo1, org.eclipse.foo2"

But then I ran a few tests, and discovered that a bundle is not being activated upon a resource request - only class request activates a bundle. I was able to access my resource file and read its content without triggering bundle Activator.start.

So the question is:

  • Is a bundle being activated upon a resource request? If it's not, it appears the documentation is misleading.
  • If it is being activated, how a non-java file can be added to the exclude/include list? Why the Activator.start isn't being triggered?

Solution

  • The actual OSGi specification for Bundle-ActivationPolicy says:

    By default, any class loaded from the bundle can trigger the lazy activation, however, resource loads must not trigger the activation. The lazy activation policy can define which classes cause the activation with the following directives:

    • include - A list of package names that must trigger the activation when a class is loaded from any of these packages. The default is all package names present in the bundle.

    • exclude - A list of package names that must not trigger the activation of the bundle when a class is loaded from any of these packages. The default is no package names.

    (section 4.4.6.2 OSGi Core Release 6 June 2014)

    So that is saying resources never trigger activation.