2015-10-26 84 views
1

我正在開發http客戶端應用程序作爲OSGI捆綁項目,我使用apache maven創建項目文件夾結構,使用下面的命令。OSGI包在Apache Servicemix中未啓動

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安裝在本地的倉庫

它創造所需的jar文件。

問題從這裏開始。我試圖部署它已經安裝了束中的Apache ServiceMix的束,但在啓動捆綁它給了一個錯誤

我已經以下命令中的ServiceMix殼

OSGi的執行:安裝MVN:com.techiyhub/integration.sms /1.0-SNAPSHOT

它得到了與包ID安裝,那麼我下面的命令執行

的OSGi:啓動302

它給了以下錯誤

錯誤執行命令:錯誤起始束: 無法啓動束302:在束integration.sms未解決的約束[302]:無法解析302.0:錯過 荷蘭國際集團的要求[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) 

請幫我出這一點。

回答

2

當您創建一個包時,maven bundle插件會掃描您的項目的所有使用包的類文件。它在Manifest中爲這些創建Import-Package語句。

然後在運行時,您必須確保您還安裝了運行您的軟件包所需的所有必要庫。錯誤消息可幫助您找到要安裝的正確捆綁包。所以在你的情況下,你必須安裝一個導出包org.apache.http的包。

在你的情況下,這些都是:

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

謝謝@Christain施耐德與詳細的解釋解決方案,它幫助我學習。您的解決方案解決了問題。我很想知道如何找到正確的庫,你說「錯誤信息可以幫助你找到正確的安裝包」,它在錯誤信息中提到。 – sandeep

+0

OSGi告訴你在哪個版本範圍丟失的包。不幸的是,你必須自己找到一個匹配的包。在許多情況下,原始項目已經像上述情況一樣生成捆綁包。在其他情況下,servicemix bundles子項目可以提供幫助。我通常使用軟件包名稱在maven central上搜索。 –

+0

謝謝@Christian Schneider – sandeep

相關問題