Search code examples
javaeclipsejarosgiosgi-bundle

Running OSGI bundle from OSGI command prompt :Import-package missing constraint


I have a bundle with the following mainfest:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloCamera
Bundle-SymbolicName: HelloCamera
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: hellocamera.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: cameraservice, cameraserviceimpl, org.osgi.framework

Layout:
    HelloCamera
       -> hellocamera
            -> Activator.java

And a second bundle with this manifest:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CameraService
Bundle-SymbolicName: CameraService
Bundle-Version: 1.0.0.qualifier
Bundle-Localization: plugin
Export-Package: cameraservice, cameraserviceimpl
Import-Package: org.osgi.framework
Bundle-Activator: cameraserviceimpl.Activator

Layout:
    CameraService
       -> cameraservice
            -> CameraService.java
       -> cameraserviceimpl
            -> Activator.java 
            -> CameraServiceImpl.java

I can run the first bundle from Eclipse and everything works fine as expected. I then exported both bundles as a CameraService.jar and HelloCamera.jar respectivly

I opened up my OSGI console, java -jar equinox.jar -console and

osgi> install file:CameraService.jar
osgi> install file:HelloCamera.jar
osgi> ss
           id    State         Bundle
           17   INSTALLED      HelloCamera_1.0.0.qualifier
           18   RESOLVED       unknown_0.0.0 [18]

then I get

The Bundle could not be resolved. Reason: Missing Constraint: Import-Package: cameraservice; version="0.0.0"

Solution

  • After searching,

    I found the problem was with the manifest files. When exporting the jars in my settings I said use the manifest file already in the folder.

    I never looked at what the path was pointing to (assuming eclipse would set it correctly) however Eclipse hadn't changed its location so both jars were using the same Manifest file.

    Lesson learned. Always check the form before blindly pressing finish.