1

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?

anvarik
  • 6,417
  • 5
  • 39
  • 53

1 Answers1

4

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

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • But the problem here is the package `a.b.c` has a class named `d` and it has an inner class `e`. So when I want to import `a.b.c.d.e` I am getting following error: `Bundle exports packages which are not in the bundle classpath`. Any idea on that? – anvarik Mar 12 '13 at 11:31
  • Oh this is really confusing because you made your class names look like package names. So if you have classes inside package `a.b.c` then you only import/export package `a.b.c`. There is no package called `a.b.c.d.e` because d and e are classes. – Neil Bartlett Mar 12 '13 at 12:25
  • yes I thought/did the same. Only imported/exported `a.b.c` but I am getting the error saying that package `a.b.c.d.e` is missing. I know that `a.b.c.d.e` is not a package but that's what error says :( want me to provide some screenshots? I think i could not make myself clear enoguh – anvarik Mar 12 '13 at 12:55
  • It looks like you have an Export-Package line that includes `a.b.c.d.e`. Remove that. If this is not the actual problem then yes, screenshots will help. – Neil Bartlett Mar 12 '13 at 13:04
  • I did as you told, but still having that error on Eclipse. So here is how my bundlemanifest[http://tinypic.com/r/23hsr5l/6] looks like. As you see I imported mapacess package. And here[http://tinypic.com/r/iznr5v/6] as you see now it asks me to add mapaccess.TrafficState package... – anvarik Mar 12 '13 at 13:22
  • Right. So add `mapaccess.IRoadElement` and `mapaccess.TrafficState`. – Neil Bartlett Mar 12 '13 at 13:28
  • So it comes to the beginning :) I added them, but in that case my Knopflerfish throwing an error, `Unable to resolve bundle: missing package(s) or can not resolve all of the them: eu.ecomoveproject.ecomap.mapaccess.TrafficState, eu.ecomoveproject.ecomap.mapaccess.IRoadElement` I think it is because `ecomap` project does not export those two above, but I cannot add them to its manifest's exported-packages section because whenever I try that case I am getting `Bundle exports packages which are not in the bundle classpath`... – anvarik Mar 12 '13 at 13:35
  • Your reasoning is fine so far. The error message when you add the packages as exports means that the packages aren't actually inside the bundle. Please show the contents of that bundle. – Neil Bartlett Mar 12 '13 at 13:47
  • hm here is the `ecomap` project's bundle: Import-Package: org.osgi.framework Export-Package: eu.ecomoveproject.ecomap.locationreferencing, eu.ecomo veproject.ecomap.mapaccess, eu.ecomoveproject.ecomap.util, eu.ecomove project.ecomap.vehicleposition, eu.ecomoveproject.ecomap.ecorouting – anvarik Mar 12 '13 at 13:50
  • and whenever I want to add those eu.ecomoveproject.ecomap.mapaccess.TrafficState, eu.ecomoveproject.ecomap.mapaccess.IRoadElement two classes to the bundle I am getting the error above: Bundle exports packages which are not in the bundle classpath – anvarik Mar 12 '13 at 13:54
  • No I need to see the full MANIFEST.MF of "ecomap" **and its contents**. – Neil Bartlett Mar 12 '13 at 13:55
  • And PLEASE BE CAREFUL with your terminology!! A class is a class and a package is a package. If you say class when you mean package, or vice versa, you make it MUCH HARDER to help you. – Neil Bartlett Mar 12 '13 at 13:58
  • here is the manifest: `Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: ecomap Bundle-ManifestVersion: 2 Bundle-SymbolicName: ecomap Import-Package: org.osgi.framework Export-Package: eu.ecomoveproject.ecomap.locationreferencing, eu.ecomo veproject.ecomap.mapaccess, eu.ecomoveproject.ecomap.util, eu.ecomove project.ecomap.vehicleposition, eu.ecomoveproject.ecomap.ecorouting` – anvarik Mar 12 '13 at 14:11