Question

I have one bundle B1 using another bundle B2 and bundle B2 exports following packages:

  • package a.b.c
  • package a.b.d

The problem here is in B1 I need to use some inner classes in package a.b.c, lets say: a.b.c.d.e But in that case eclipse throws following error:

The package a.b.c.d.e is used but not imported in manifest.

but I already made B2 to export/B1 to import a.b.c package! Why I need to insert the inner class again?

Was it helpful?

Solution

This just looks like a misunderstanding of how packages work in Java.

Packages are NOT hierarchical, even though they may appear to be. So package a.b.c.d.e is not a "child" package of a.b.c in any sense. They are just two different packages with different names.

So if you have used classes from package a.b.c.d.e then you need to import package a.b.c.d.e. The fact that you may also have imported a.b.c is irrelevant.

UPDATE to summarize the discussion in comments/chat below:

  1. The error "package xyz is used but not imported in manifest" means that the package needs to be added to Import-Package, and note that packages are not nested so each individual package does need to be imported.

  2. If adding that package to Import-Package results in a resolution error, it means there is no existing bundle that exports the package. Whichever bundle contains the package in question should list it in Export-Package.

  3. If the result is now the error message "Bundle exports packages which are not in the bundle classpath" then the bundle with the export doesn't actually contain the package in its contents. Probably you have added the export statement to the wrong bundle, or somehow the package has been incorrectly omitted from the contents of the bundle. The reason for this happening depends on the build system that you are using.

Finally: don't get classes and packages mixed up! Packages are the things we import/export in OSGi. When a package is exported or imported, it always applies to all of the classes in that package, including "inner classes".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top