OSGI Bundle Dependencies

I have created a package that relies on SLF4J and as such I am using Logback to implement OSGI. This ties everything together and sets OK, but when I go to run the package, I get the following exception:

org.osgi.framework.BundleException: Unable to resolve com.felix.test [20] (R 20.0): Missing requirement [com.felix.test [20] (R 20.0)] osgi.wiring.package; (osgi.wiring.package = groovy.lang) Unresolved requirements: [[com.felix.test [20] (R 20.0)] osgi.wiring.package; (Osgi.wiring.package = groovy.lang)]

I can see in my manifest file it groovy.lang

is listed in Import-Package

, and I'm pretty sure the problem is that the Logback is being injected, but none of the links are.

I am using to create a package, here's config:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.5.4</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Import-Package>
                *
            </Import-Package>
            <Embed-Dependency>
                *
            </Embed-Dependency>
            <Embed-Directory>
                osgi-inf/libs
            </Embed-Directory>
            <Embed-Transitive>
                true
            </Embed-Transitive>
        </instructions>
    </configuration>
</plugin>

      

Here is my manifest:

Manifest-Version: 1.0
Bnd-LastModified: 1436982944102
Build-Jdk: 1.8.0_45
Built-By: tim.clifford
Bundle-ClassPath: .,osgi-inf/libs/org.osgi.core-1.0.0.jar,osgi-inf/libs/
 servlet-api-2.5.jar,osgi-inf/libs/org.apache.felix.scr.annotations-1.9.
 6.jar,osgi-inf/libs/httpclient-osgi-4.5.jar,osgi-inf/libs/httpclient-4.
 5.jar,osgi-inf/libs/httpcore-4.4.1.jar,osgi-inf/libs/commons-logging-1.
 2.jar,osgi-inf/libs/commons-codec-1.9.jar,osgi-inf/libs/httpmime-4.5.ja
 r,osgi-inf/libs/httpclient-cache-4.5.jar,osgi-inf/libs/fluent-hc-4.5.ja
 r,osgi-inf/libs/ehcache-2.10.0.jar,osgi-inf/libs/slf4j-api-1.7.7.jar,os
 gi-inf/libs/commons-lang3-3.4.jar,osgi-inf/libs/logback-classic-1.1.3.j
 ar,osgi-inf/libs/logback-core-1.1.3.jar
Bundle-ManifestVersion: 2
Bundle-Name: com.felix.test
Bundle-SymbolicName: com.felix.test
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *
Embed-Directory: osgi-inf/libs
Embed-Transitive: true
Embedded-Artifacts: osgi-inf/libs/org.osgi.core-1.0.0.jar;g="org.apache.
 felix";a="org.osgi.core";v="1.0.0",osgi-inf/libs/servlet-api-2.5.jar;g=
 "javax.servlet";a="servlet-api";v="2.5",osgi-inf/libs/org.apache.felix.
 scr.annotations-1.9.6.jar;g="org.apache.felix";a="org.apache.felix.scr.
 annotations";v="1.9.6",osgi-inf/libs/httpclient-osgi-4.5.jar;g="org.apa
 che.httpcomponents";a="httpclient-osgi";v="4.5",osgi-inf/libs/httpclien
 t-4.5.jar;g="org.apache.httpcomponents";a="httpclient";v="4.5",osgi-inf
 /libs/httpcore-4.4.1.jar;g="org.apache.httpcomponents";a="httpcore";v="
 4.4.1",osgi-inf/libs/commons-logging-1.2.jar;g="commons-logging";a="com
 mons-logging";v="1.2",osgi-inf/libs/commons-codec-1.9.jar;g="commons-co
 dec";a="commons-codec";v="1.9",osgi-inf/libs/httpmime-4.5.jar;g="org.ap
 ache.httpcomponents";a="httpmime";v="4.5",osgi-inf/libs/httpclient-cach
 e-4.5.jar;g="org.apache.httpcomponents";a="httpclient-cache";v="4.5",os
 gi-inf/libs/fluent-hc-4.5.jar;g="org.apache.httpcomponents";a="fluent-h
 c";v="4.5",osgi-inf/libs/ehcache-2.10.0.jar;g="net.sf.ehcache";a="ehcac
 he";v="2.10.0",osgi-inf/libs/slf4j-api-1.7.7.jar;g="org.slf4j";a="slf4j
 -api";v="1.7.7",osgi-inf/libs/commons-lang3-3.4.jar;g="org.apache.commo
 ns";a="commons-lang3";v="3.4",osgi-inf/libs/logback-classic-1.1.3.jar;g
 ="ch.qos.logback";a="logback-classic";v="1.1.3",osgi-inf/libs/logback-c
 ore-1.1.3.jar;g="ch.qos.logback";a="logback-core";v="1.1.3"
Export-Package: com.felix.test;version="1.0.0"
Import-Package: groovy.lang,javax.crypto,javax.crypto.spec,javax.jms,jav
 ax.mail,javax.mail.internet,javax.management,javax.management.openmbean
 ,javax.naming,javax.naming.directory,javax.naming.ldap,javax.net,javax.
 net.ssl,javax.security.auth.x500,javax.sql,javax.swing.event,javax.tran
 saction,javax.transaction.xa,javax.xml.datatype,javax.xml.namespace,jav
 ax.xml.parsers,javax.xml.stream,javax.xml.stream.events,net.spy.memcach
 ed,org.apache.avalon.framework.logger,org.apache.felix.scrplugin,org.ap
 ache.felix.scrplugin.annotations,org.apache.felix.scrplugin.description
 ,org.apache.log,org.apache.log4j,org.codehaus.commons.compiler,org.code
 haus.groovy.control,org.codehaus.groovy.control.customizers,org.codehau
 s.groovy.reflection,org.codehaus.groovy.runtime,org.codehaus.groovy.run
 time.callsite,org.codehaus.groovy.runtime.typehandling,org.codehaus.gro
 ovy.runtime.wrappers,org.codehaus.groovy.transform,org.codehaus.janino,
 org.hibernate,org.hibernate.cache,org.hibernate.cache.access,org.hibern
 ate.cfg,org.hibernate.impl,org.hibernate.stat,org.hibernate.transaction
 ,org.ietf.jgss,org.osgi.service.cm,org.quartz,org.quartz.impl,org.quart
 z.impl.jdbcjobstore,org.quartz.impl.matchers,org.quartz.simpl,org.terra
 cotta.quartz,org.terracotta.toolkit,org.terracotta.toolkit.atomic,org.t
 erracotta.toolkit.builder,org.terracotta.toolkit.cache,org.terracotta.t
 oolkit.cluster,org.terracotta.toolkit.collections,org.terracotta.toolki
 t.concurrent.locks,org.terracotta.toolkit.config,org.terracotta.toolkit
 .events,org.terracotta.toolkit.feature,org.terracotta.toolkit.internal,
 org.terracotta.toolkit.internal.cache,org.terracotta.toolkit.internal.c
 luster,org.terracotta.toolkit.internal.collections,org.terracotta.toolk
 it.internal.concurrent.locks,org.terracotta.toolkit.internal.feature,or
 g.terracotta.toolkit.monitoring,org.terracotta.toolkit.nonstop,org.terr
 acotta.toolkit.rejoin,org.terracotta.toolkit.search,org.terracotta.tool
 kit.search.attribute,org.terracotta.toolkit.store,org.xml.sax,org.xml.s
 ax.helpers,sun.misc,sun.reflect
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Tool: Bnd-2.4.1.201501161923

      

Am I on the right track or is there a better method?

Thank!

+3


source to share


3 answers


To your question: "I am walking, this is the right way", the answer is "definitely not"!

Please don't useEmbed-Dependency

. It just takes the entire transitive dependency graph (which in your case includes Groovy language execution, somehow) and inserts it inside your package.



This completely eliminates the OSGi dot. Even worse, when you develop your next package, you'll have to go through it all again! You will end up with dozens of bundles, each containing a massive, dead weight of inline dependencies.

As Christian said, stick with the defaults provided maven-bundle-plugin

. You don't even need to specify <Import-Package>*</Import-Package>

, as this is already the default. This will end up with a package that has package imports, which is good! But you need to install packages that provide exports that match your imports.

+4


source


You don't have to embed all dependencies in your package. Instead, just run with the maven bundle plugin settings. It should create a package, which can then be deployed to an OSGi container.

Most of all I like the Apache karaf . There you can simply install the package using:

install -s mvn:groupId/artifactId/version

      



In your case, this may already work, since Apache Karaf comes with the pax protocol pre-installed.

If you want to use a simple felix, it is a little more complicated as you will need to collect all the dependencies and create a suitable initial configuration. This is where bndtools can help.

+4


source


From the exception you reported in your question, I would say that none of the packages in your osgi environment currently export a package groovy.lang

. I would suggest installing the felix gogo shell at runtime and issuing the following command in the osgi console:

g! inspect cap osgi.wiring.package

      

This will give you a list of all exported packages in your osgi instance: this way you can check if the package is groovy.lang

really missing.

If so, then you should wrap the groovy -all jar in the bundle as described here and include it in your running osgi packages. If you'd like, you can find a ready-to-use osgi package for groovy -all on the jpm4j website .

0


source







All Articles