Search code examples
osgikaraf

Karaf: Bundles Instances and classloaders


Is each Karaf bundle loaded by a separate classloader?

Are all bundles of a feature loaded by the SAME classloader?

If I include a dependent feature in a new feature I am trying to develop, would the bundles of that feature use the SAME classloader as the feature I am trying to develop?


Solution

  • In OSGi in general each bundle has its own classloader. This classloader serves the classes of the bundle and delegates to the classloader of bundles this bundle imports packages from. So basically each class is normally loaded by the classloader of the bundle the class resides in. The Import-Package and Export-Package statements in the Manifest and the OSGi resolver then make sure bundles can also see the classes of other bundles.

    Karaf features are completely unrelated to classloaders. They simply define which bundles are loaded.