Search code examples
javamavenosgiblueprint-osgi

OSGi os.wiring.package error when starting bundle in Karaf


I'm diving into OSGi land and built a bundle that I'm trying to install into Karaf. I'm getting the following error:

I'm wondering if it's the way blueprint is working or if I'm somehow not exporting/importing the modules correctly?

I'm using blueprint, I have the impl blueprint looking like the following:

blueprint file for impl

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:cxf="http://cxf.apache.org/blueprint/core"
           xmlns:jaxrs="http://cxf.apache.org/schemas/jaxrs.xsd"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://cxf.apache.org/blueprint/core ">

    <cxf:bus id="greetingServiceBus">
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>

    <bean id="welcomeImpl" class="welcomeimpl.WelcomeImpl"/>
    <service ref="welcomeImpl" interface="welcome.WelcomeAPI"/>

    <jaxrs:server address="/tester" id="tester">
        <jaxrs:serviceBeans>
            <ref component-id="welcomeImpl"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>
</blueprint>

error

Error executing command: Error executing command on bundles: Error starting bundle 119: Unable to resolve impl [119](R 119.0): missing requirement [impl [119](R 119.0)] osgi.wiring.package; (osgi.wiring.package=welcome) Unresolved requirements: [[impl [119](R 119.0)] osgi.wiring.package; (osgi.wiring.package=welcome)]

impl POM.xml

   <parent>
        <artifactId>learning-osgi</artifactId>
        <groupId>com.osgirest</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <packaging>bundle</packaging>

    <artifactId>impl</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.osgirest</groupId>
            <artifactId>welcome-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Export-Package>
                            javax.ws.rs*,
                            com.learning.welcomeimpl
                        </Export-Package>
                        <Import-Package>
                            *,
                            javax.ws.rs*
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

api POM.xml

<parent>
    <artifactId>learning-osgi</artifactId>
    <groupId>com.osgirest</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>welcome-api</artifactId>
<packaging>bundle</packaging>

<name>welcome-api Bundle</name>
<description>api to welcome people into the application</description>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Bundle-Activator/>
                    <Export-Package>
                        com.learning.welcome;version=${project.version}
                    </Export-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

Directory structure

├── impl
│   ├── impl.iml
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── learning
│   │   │   │           └── welcomeimpl
│   │   │   │               └── WelcomeImpl.java
│   │   │   └── resources
│   │   │       └── OSGI-INF
│   │   │           └── blueprint
│   │   │               └── blueprint.xml
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   ├── META-INF
│       │   │   └── MANIFEST.MF
│       │   ├── OSGI-INF
│       │   │   └── blueprint
│       │   │       └── blueprint.xml
│       │   └── com
│       │       └── learning
│       │           └── welcomeimpl
│       │               └── WelcomeImpl.class
│       ├── generated-sources
│       │   └── annotations
│       ├── impl-1.0-SNAPSHOT.jar
│       └── maven-status
│           └── maven-compiler-plugin
│               ├── compile
│               │   └── default-compile
│               │       ├── createdFiles.lst
│               │       └── inputFiles.lst
│               └── testCompile
│                   └── default-testCompile
│                       └── inputFiles.lst
├── learningosgi.iml
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│       └── java
└── welcomeapi
    ├── pom.xml
    ├── src
    │   ├── main
    │   │   ├── java
    │   │   │   └── com
    │   │   │       └── learning
    │   │   │           └── welcome
    │   │   │               └── WelcomeAPI.java
    │   │   └── resources
    │   └── test
    │       └── java
    ├── target
    │   ├── classes
    │   │   ├── META-INF
    │   │   │   └── MANIFEST.MF
    │   │   └── com
    │   │       └── learning
    │   │           └── welcome
    │   │               └── WelcomeAPI.class
    │   ├── generated-sources
    │   │   └── annotations
    │   ├── maven-status
    │   │   └── maven-compiler-plugin
    │   │       ├── compile
    │   │       │   └── default-compile
    │   │       │       ├── createdFiles.lst
    │   │       │       └── inputFiles.lst
    │   │       └── testCompile
    │   │           └── default-testCompile
    │   │               └── inputFiles.lst
    │   └── welcome-api-1.0-SNAPSHOT.jar
    └── welcomeapi.iml

Solution

  • There are some problems in your example but let´s start with what you should aim for.

    In each bundle you want to export the packages that other bundles should see and you want to import all packages your bundle needs. The good news is that the maven-bundle-plugin does a great job in figuring these out.

    For the imports normally simply do not define anything. The plugin almost always does the right thing.

    For the exports your API bundle wants to export com.learning.welcome and the impl bundle does not need to export anything. By default the bundle plugin exports all packages except those that have special names like impl. So again defaults will do the right thing. Simply do not define any imports and exports in both bundles and it will be correct.

    The last thing is the blueprint. Like Alessandro explained you used the wrong packages there. The maven bundle plugin also looks into your blueprint to figure out the imports. So it will import the non existant package "welcome" which of course is not exported by any bundle. This problem has also hit me a lot when I did a refactoring and the blueprint stayed the same.