Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the private-package manifest header do?

Tags:

java

osgi

bnd

I am familiar with Import-Package and Export-Package, but this is a new one for me. What does it do?

like image 772
Midhat Avatar asked Nov 22 '12 13:11

Midhat


People also ask

What is the purpose of the export package manifest header?

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.

What is bundle classpath?

A Bundle-Classpath is an ordered, comma-separated list of relative bundle JAR file locations to be searched for class and resource requests.

What is OSGi import package?

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.

What is a bundle manifest?

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.


2 Answers

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.*

like image 187
Martin Ellis Avatar answered Oct 17 '22 20:10

Martin Ellis


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.

like image 23
Christian Schneider Avatar answered Oct 17 '22 21:10

Christian Schneider