Skip to content
Advertisement

Simple OSGi application with dependencies inside bundle

Simple OSGi application with dependencies inside bundle.

I am playing with karaf. I started by writing a simple rest application. https://github.com/YaroslavTir/osgi-jersey-hibertate/tree/stackoverflow/examples/karaf-rest-core

I took karaf examples as backbond and it was quite simple to run my first bundle with rest endpoints, but then I faced an issue when I added maven dependency. I added guava as an example and got an exception when installing the bundle in karaf

 <dependencies>
       ...
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>29.0-jre</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>org.apache.karaf.core.rest.blueprint</Export-Package>
                        <Import-Package>
                            *
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>


> git clone https://github.com/YaroslavTir/osgi-jersey-hibertate
> mvn clean install 
> feature:repo-add mvn:org.apache.karaf.examples/karaf-rest-core-features/LATEST/xml
> feature:install karaf-rest-core-blueprint

Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=karaf-rest-core-blueprint; type=karaf.feature; version=”[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]”; filter:=”(&(osgi.identity=karaf-rest-core-blueprint)(type=karaf.feature)(version>=4.3.1.SNAPSHOT)(version<=4.3.1.SNAPSHOT))” [caused by: Unable to resolve karaf-rest-core-blueprint/4.3.1.SNAPSHOT: missing requirement [karaf-rest-core-blueprint/4.3.1.SNAPSHOT] osgi.identity; osgi.identity=org.apache.karaf.examples.karaf-rest-core-blueprint; type=osgi.bundle; version=”[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]”; resolution:=mandatory [caused by: Unable to resolve org.apache.karaf.examples.karaf-rest-core-blueprint/4.3.1.SNAPSHOT: missing requirement [org.apache.karaf.examples.karaf-rest-core-blueprint/4.3.1.SNAPSHOT] osgi.wiring.package; filter:=”(&(osgi.wiring.package=com.google.common.collect)(version>=29.0.0)(!(version>=30.0.0)))”]]

I read somewhere that org.apache.felix.maven-bundle-plugin has a bug and add optional dependency to the bundle, and this looks like true, as I can see in MANIFEST.MF/Import-Package dependncy like com.google.appengine.api that should not be there. :

   <dependencies>
       ...
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>29.0-jre</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>org.apache.karaf.core.rest.blueprint</Export-Package>
                        <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Embed-Directory>target/dependency</Embed-Directory>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

I know that should be super simple, and I just miss some small but important detail.

Advertisement

Answer

Your error means that your bundle karaf-rest-core-blueprint has a dependency on com.google.common.collect and this dependency can’t be resolved in the container.

In other words, you did’nt install guava into Karaf.

$ bundle:install -s mvn:com.google.guava/failureaccess/1.0.1
$ bundle:install -s mvn:com.google.guava/guava-29.0-jre

In a real app, you should create a feature which installs all your dependencies/bundles.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement