Mirco
Mirco

Reputation: 3016

Whats the deal with private packages?

I have been working with OSGi for a while now, but I still don't understand something about private packages.

Aren't all bundle packages which are not exported invisible to all other packages? If so, what's the difference to private packages and packages which are not exported?

I've read OSGi in Action and "OSGi and Apache Felix 3.0 - Beginners Guide", but i was not able to find the difference.

Upvotes: 29

Views: 10659

Answers (2)

benjamin
benjamin

Reputation: 1066

Yes, all packages not defined in the manifest.mf entry Export-Package are private packages. You don't need to specify them seperately, it's just another term for the ease of communication.

If you have your manifest generated as for example by the maven-bundle-plugin, this term get's a little more relevant, because the maven bundle plugin will per default export all packages, except for example a package called internal (or subpackages of that). This is somehow the inverse approach since you specify the private packages and have the exported package calculated. See the maven bundle plugin for details.

Upvotes: 21

Neil Bartlett
Neil Bartlett

Reputation: 23948

There is no difference.

Any package which is not listed in Export-Package is private.... that's all there is to it.

You may have seen another header called Private-Package. This is NOT an OSGi header and it is completely ignored by the OSGi Framework. If you see this it indicates that a bundle has been built with bnd or the Maven Bundle Plugin, which uses this header has a build-time instruction. It's therefore only relevant at build time, and has no effect whatsoever at run time.

Upvotes: 28

Related Questions