OSGI捆绑包依赖性 [英] OSGI bundle dependencies

查看:181
本文介绍了OSGI捆绑包依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个依赖于SLF4J的分发包,因此我将Logback用于OSGI实现.这些全部捆绑并安装确定,但是当我开始启动捆绑包时,出现以下异常:

I have created an bundle which relies on SLF4J and as such am using Logback for the OSGI implementation. This all bundles up and installs OK but when I come to start the bundle I get the following exception:

org.osgi.framework.BundleException:无法解析com.felix.test [20](R 20.0):缺少要求[com.felix.test [20](R 20.0)] osgi.wiring.package; (osgi.wiring.package = groovy.lang)尚未解决 要求:[[com.felix.test [20](R 20.0)] osgi.wiring.package; (osgi.wiring.package = groovy.lang)]

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)]

我可以在清单文件groovy.lang中看到Import-Package,我很确定问题是已嵌入Logback,但没有引用.

I can see in my manifest file groovy.lang is listed in Import-Package and I'm pretty sure the problem is that Logback is being embedded but none of it's references are.

我用来创建捆绑包,这是配置:

I'm using to create the bundle, here's the 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>

这是我的清单:

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 going about it the right way or is there a better method?

谢谢!

推荐答案

对于您的问题我要走的路是正确的",答案是肯定不是"!

To your question "am I going about is the right way", the answer is "definitely not"!

请,请不要使用Embed-Dependency .这只是简单地获取了所有传递性依赖关系图(在您的情况下,它包括Groovy语言运行时),并将其粘贴到包中.

Please, please don't use Embed-Dependency. This simply takes all of the transitive dependency graph (which in your case includes the Groovy language runtime, somehow) and sticks it inside your bundle.

这完全错过了OSGi的要点.更糟糕的是,在开发下一个捆绑软件时,您将不得不再次经历所有这些!最终,您将拥有数十个捆绑包,每个捆绑包都承载着沉重的嵌入式依赖项.

This misses the point of OSGi entirely. Worse, when you develop your next bundle you will have to go through all this again! Eventually you will have tens of bundles, each carrying around a massive, dead weight of embedded dependencies.

正如克里斯蒂安所说,请遵守maven-bundle-plugin提供的默认设置.您甚至无需指定<Import-Package>*</Import-Package>,因为这已经是默认设置.结果,您将获得一个包含程序包导入的捆绑包,这是一件好事!但是您需要安装提供与您的进口匹配的出口的捆绑软件.

As Christian said, stick to the defaults provided by the maven-bundle-plugin. You don't even need to specify <Import-Package>*</Import-Package> since this is already the default. As a result you will get a bundle that has package imports, which is a good thing! But you need to install bundles that provide exports that will match your imports.

这篇关于OSGI捆绑包依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆