I am familiar with Import-Package
and Export-Package
, but this is a new one for me. What does it do?
This header declares the external dependencies of the bundle that the OSGi Framework uses to resolve the bundle. Specific versions or version ranges for each package can be declared.
A Bundle-Classpath is an ordered, comma-separated list of relative bundle JAR file locations to be searched for class and resource requests.
OSGi allows for dependencies to be determined via Import-Package , which just wires up a single package (exported from any bundle), and Require-Bundle , which wires up to a specific named bundle's exports.
The bundle manifest file is an XML document that contains a list of app packages and resource packages in the bundle. The bundle manifest contains info about the architectures and resources of each package.
At runtime in the OSGi container it does nothing. In fact, it's not even mentioned in the OSGi specification (I checked R4).
However, it can be specified in a .bnd
file for use by bnd at build time. If so, it can be used to determine what goes into the bundle.
When bnd builds a bundle, it automatically determines which classes need to go into the bundle. All the classes in packages that are exported are included, and all the classes that they depend on (transitively) are included too. This means that if a class doesn't appear to be used, then it won't be included in the bundle. However, you can use the Private-Package instruction to tell bnd to include the contents of the package in the bundle, even if it appears to be unused. If the Private-Package instruction is not specified, then it will be automatically generated by bnd.
The documentation for Private-Package reads as follows:
Private Package
The method of inclusion is identical to the Export-Package header, the only difference is, is that these packages are not exported. This header will be copied to the manifest. If a package is selected by noth the export and private package headers, then the export takes precedence.
Private-Package= com.*
In fact Private-Package does more than just not exporting a package. If the packages specified in Private-Package are not defined inside you own project and are not imported in Import-Package then they are automatically inlined into your jar. So this is an easy way to include non OSGi dependencies. Be careful though that inlining can easily lead to classpath problems.
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