【问题标题】:OSGI bundle is not getting started in Apache ServicemixOSGI 包未在 Apache Servicemix 中启动
【发布时间】:2016-01-25 09:10:40
【问题描述】:

我正在将 http 客户端应用程序开发为 OSGI 捆绑项目,我使用 apache maven 创建项目文件夹结构,用于以下命令。

mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-blueprint-archetype -DarchetypeVersion=2.3.7 -DgroupId=com.techiyhub -DartifactId=integration.sms -Dversion=1.0-SNAPSHOT -Dpackage=com.techiyhub.integration.sms

上面的命令创建了项目文件夹结构,因为我正在使用基于 httpclient 的应用程序。我在 pom.xml 中添加了如下依赖项。

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>com.techiyhub</groupId>
<artifactId>integration.sms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>integration.sms Blueprint Bundle</name>
<description>integration.sms OSGi blueprint bundle project.</description>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.4.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Export-Package>
                        com.techiyhub.integration.sms*;version=${project.version}
                    </Export-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.5</version>
    </dependency>       
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.0.4</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.6</version>
    </dependency>
</dependencies> 

我执行了下面的命令,

mvn 安装

它在本地 maven 存储库中创建了所需的 jar 文件。

问题从这里开始。我试图在 apache servicemix 中部署捆绑包,它已经安装了捆绑包,但是在启动捆绑包时出现错误

我在 servicemix shell 中执行了以下命令

osgi:install mvn:com.techiyhub/integration.sms/1.0-SNAPSHOT

它是使用捆绑包 id 安装的,然后我在命令下执行

osgi:开始 302

它给出了以下错误

执行命令时出错:启动捆绑包时出错: 无法启动捆绑包 302:捆绑包 integration.sms [302] 中未解决的约束:无法解析 302.0:错过 ing 要求 [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)

完整的错误堆栈跟踪如下

2015-10-26 14:33:12,551 | ERROR | l Console Thread | Console                          | 22 - org.apache.karaf.shell.cons
ole - 2.4.3 | Exception caught while executing command
org.apache.karaf.shell.console.MultiException: Error starting bundles:
        Unable to start bundle 302: Unresolved constraint in bundle integration.sms [302]: Unable to resolve 302.0: miss
ing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
        at org.apache.karaf.shell.console.MultiException.throwIf(MultiException.java:91)
        at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:43)
        at org.apache.karaf.shell.osgi.BundlesCommand.doExecute(BundlesCommand.java:37)
        at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:38)
        at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)
        at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_80]
        at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_80]
        at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)[16:org.apache.aries.proxy.impl:1.0.4]

        at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)[16:org.apache.aries.proxy.impl:1.0.4]
        at org.apache.karaf.shell.console.commands.$BlueprintCommand22803378.execute(Unknown Source)[22:org.apache.karaf
.shell.console:2.4.3]
        at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[22:org.apache.karaf.shell.console:2.
4.3]
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[22:org.apache.karaf.shell.console:2.4.3]
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[22:org.apache.karaf.shell.console:2.
4.3]
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[22:org.apache.karaf.shell.console:2.4.3]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[22:org.apache.karaf.shell.console:2.4.3]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[22:org.apache.karaf.shell.console:2.4.3]
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:92)[22:org.apache.karaf.shel
l.console:2.4.3]
        at org.apache.karaf.shell.console.jline.Console.run(Console.java:195)[22:org.apache.karaf.shell.console:2.4.3]
        at org.apache.karaf.shell.console.jline.DelayedStarted.run(DelayedStarted.java:79)[22:org.apache.karaf.shell.con
sole:2.4.3]
Caused by: java.lang.Exception: Unable to start bundle 302: Unresolved constraint in bundle integration.sms [302]: Unabl
e to resolve 302.0: missing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
        at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:39)
        ... 18 more
Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle integration.sms [302]: Unable to resolve
302.0: missing requirement [302.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4002)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2045)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963)
        at org.apache.karaf.shell.osgi.StartBundle.doExecute(StartBundle.java:37)
        ... 18 more


        Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle : Unable to resolve: missing requirement [302.0] osgi.wiring.package;(osgi.wiring.package=org.apache.http)

请帮我解决这个问题。

【问题讨论】:

    标签: osgi httpclient apache-karaf blueprint-osgi apache-servicemix


    【解决方案1】:

    当您创建一个包时,maven 包插件会扫描您项目的类文件以查找所有使用的包。它在 Manifest 中为这些创建 Import-Package 语句。

    然后在运行时,您必须确保还安装了运行包所需的所有必要库。该错误消息可帮助您找到要安装的正确捆绑包。因此,在您的情况下,您必须安装一个导出包 org.apache.http 的包。

    在你的情况下,这些是:

    mvn:org.apache.httpcomponents/httpcore-osgi/4.3.3
    mvn:org.apache.httpcomponents/httpclient-osgi/4.3.6
    

    【讨论】:

    • 感谢@Christain Schneider 提供详细解释的解决方案,它帮助我学习。问题已通过您的解决方案得到解决。我很想知道如何找到正确的库,您说“错误消息可以帮助您找到要安装的正确包”,错误消息中提到了它。
    • OSGi 告诉您缺少哪个版本范围的哪个软件包。不幸的是,您必须自己找到匹配的捆绑包。在许多情况下,原始项目已经像上面的例子一样生成了捆绑包。在其他情况下,servicemix 捆绑子项目可以提供帮助。我通常使用包名在 maven central 上搜索。
    • 谢谢@Christian Schneider
    猜你喜欢
    • 2018-04-17
    • 2014-01-12
    • 2014-12-01
    • 2018-12-28
    • 2015-10-19
    • 2011-05-21
    • 2011-03-27
    • 2015-02-16
    • 2014-03-18
    相关资源
    最近更新 更多