3

I have a Vaadin application, which I'm trying to build as a set of OSGI bundles using Maven + BND.

I can't deploy the bundles To Apache Felix because some dependencies can't be resolved. Apache Felix complains that can't find package XYZ required by bundle "A", although this package is defined in this same bundle!!

I looked at the MANIFEST.MF file generated by Maven + BND and saw that the package (XYZ) from this bundle is added to both "import" and "export" sections. I understand why "export", but why "import"?? Why is the bundle trying to import its own package?

my MANIFEST.MF

Manifest-Version: 1.0
Export-Package: myexample.admin;uses:="com.vaadin.ui,myexample.webshared,
 com.vaadin.terminal,myexample.mvc.view.impl,
 myexample.mvc.model,myexample.mvc.renderer.map.impl,
 myexample.mvc.renderer,myexample.mvc.model.impl,myexample.util"
Built-By: ask
Tool: Bnd-0.0.384
Bundle-Name: admin
Created-By: 1.6.0_21 (Sun Microsystems Inc.)
Bundle-Version: 0
Build-Jdk: 1.6.0_26
Bnd-LastModified: 1315674240833
Bundle-ManifestVersion: 2
Import-Package: myexample.admin;version="1.0",myexample.mvc.model,
 myexample.mvc.model.impl,myexample.mvc.renderer,
 myexample.mvc.renderer.map.impl,myexample.mvc.view.impl,
 myexample.util,myexample.webshared,com.vaadin.terminal,com.vaadin.ui
Bundle-SymbolicName: admin
Include-Resource: ..\classes
Originally-Created-By: Apache Maven Bundle Plugin
Robert
  • 39,162
  • 17
  • 99
  • 152
Alex
  • 2,589
  • 3
  • 35
  • 44

2 Answers2

7

This is correct behaviour. The explanation is in section 3.5.6 of the OSGi core specification.

Regarding the unresolved error from Felix... this must be related to something else. Please post the actual error message.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • 'ERROR: Bundle admin [1] Error starting file:/C:/1-felix/bundle/admin-1.0.jar (org.osgi.framework.BundleException: Unresolved constraint in bundle admin [1]: Unable to resolve 1.0: missing requirement [1.0] package; (package=myexample.mvc.model) [caused by: Unable to resolve 16.0: missing requirement [16.0] package; (&(package=myexample.mvc.controller)(version>=1.0.0))]) org.osgi.framework.BundleException: Unresolved constraint in bundle admin [1]: Unable to resolve 1.0: missing requirement [1.0] package; (package=myexample.mvc.model) [caused by: Unable to resolve 16.0:' – Alex Sep 12 '11 at 04:18
  • missing requirement [16.0] package; (&(package=myexample.mvc.controller)(version> =1.0.0))] – Alex Sep 12 '11 at 04:18
  • So, just read what the error says. Your `admin` bundle cannot be resolved because the package `myexample.mvc.model` is not available. That package appears to be exported by bundle 16, but bundle 16 cannot be resolved because package `myexample.mvc.controller` is unavailable. – Neil Bartlett Sep 12 '11 at 05:45
  • bundle 16 has both myexample.mvc.model and myexample.mvc.controller packages, and it exports them, even though without specifying the version number in "export" section (which I *guess* is "1.0.0" by default?). the import part, on the other hand, requires "1.0": Import-Package: myexample.mvc.controller;version="1.0" can this be the cause? if yes, then why did BND plugin generate "export" element without "1.0" version tags while putting that into "import" section? – Alex Sep 12 '11 at 07:21
  • ok, never mind. I found that some packages were named ".impl." in the code, and BND does not export them by default. I renamed the packages and this solved this particular problem. look like the error message wasn't too specific. – Alex Sep 12 '11 at 19:20
  • What version of the specification? In the v4.3.0 spec there is no section 3.5.6. – Emil Lundberg Jul 02 '13 at 09:33
  • 1
    @EmilLundberg I took that section number from the R4.2 core spec. It looks like it moved to 3.6.6 in R4.3. – Neil Bartlett Jul 02 '13 at 09:51
2

Niel is, of course correct. To be honest though, I've been very successful with using the noimports:=true to get around this. In my applications, I usually have the following in my maven-bundle-plugin section:

<Export-package>*;noimports:=true</export-package>

This results in all of your packages being exported into OSGi, and none of them will appear in your import-package section. If you only need a couple of your exported packages to not appear in your import-package section, you can set the noimports flag for each individual package. Lastly, this syntax is from BND, so it should also work in your .bnd files.

Mike Van
  • 1,048
  • 7
  • 26