Whats the deal with private packages?

Mirco picture Mirco · Dec 14, 2012 · Viewed 8.4k times · Source

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

  • An exported package is a package with is visible to other bundles
  • An imported package is a package which is imported by a bundle exporting the package.
  • A private package is a package which is not visible to other bundles (I don't get this)

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.

Answer

Neil Bartlett picture Neil Bartlett · Dec 14, 2012

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.