OSGi Package Classpath Problem

So after looking into KnopflerFish OSGi packages on the OSGi Bundle Repository I realized something strange. Bundles import a package they export! I.E.

Bundle-SymbolicName: org.knopflerfish.bundle.console
Import-Package: org.knopflerfish.service.console,org.osgi.framework,org.osgi.service.log
Export-Package: org.knopflerfish.service.console;uses:=org.osgi.framework;specification version=1.0.0

I wondered if this was superfluous, but apparently it is not. Stupid me! I thought that the first place on the classpath would be packages in the bundle, but it is the resolved imported packages.

To test this out I created two simple bundles, A and B, each exported a package "nz" and imported it as well, this package had a class A that in its constructor sysouted different lines. Both had activators that simply created A();


Each time it was run both activators wrote the same message on the console, until you explicitly stated versions and version ranges to exclude each others package. Without the version range the package selected is always the greater version.

What this means is that I need to read more of the OSGi Sevice Platform Spec to get a better understanding of resolving issues.

0 comments:

Newer Post Older Post Home