With the import mechanism in OSGi, it is straightforward to import packages from another bundle. However, I have been unsuccessful in importing resources that exist in the "root" of the bundle.
Is it at all possible to import resources that aren't package scoped in to another bundle?
What I would like to achieve is this:
Bundle A has a file resource in the "root"
Bundle B imports bundle A:s packages and resources. Through bundle B:s ClassLoader, I'd like to be able to load the resource in bundle A as if it existed in Bundle B.
The key difference with OSGi is that a JAR is now all private, adding metadata in the manifest makes it a bundle that can safely share with other bundles. OSGi makes sure violations are detected ahead of time.
Procedure. Install the plug-in bundle into the Eclipse Equinox OSGi framework with the OSGi console. Start the Eclipse Equinox framework with the console enabled. Install the plug-in bundle in the Equinox console.
An OSGi bundle JAR file contains a JAR manifest file. This file contains metadata that enables the OSGi Framework to process the modular aspects of the bundle. Describes the version of the bundle and enables multiple versions of a bundle to be active concurrently in the same framework instance.
In OSGi, a single component is called a bundle. Logically, a bundle is a piece of functionality that has an independent lifecycle – which means it can be started, stopped and removed independently. Technically, a bundle is just a jar file with a MANIFEST. MF file containing some OSGi-specific headers.
Resources in the root of a bundle are in the "default" package, which cannot be imported or exported.
If you really must access the resources via classloader, you need to move them into a package and export that package. Otherwise you can use Bundle.getEntry()
to read resources from any location of any bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With