2016-01-27 227 views
-2

我想在我的項目中使用HttpClient。缺少需求osgi.wiring.package; (osgi.wiring.package = org.apache.http)

的pom.xml

............. 
<dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient-osgi</artifactId> 
      <version>4.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
      <version>4.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpcore</artifactId> 
      <version>4.4.4</version> 
     </dependency> 
<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <_wab>src/main/webapp/</_wab> 
         <Bundle-SymbolicName> 
          ${project.groupId}.${project.artifactId} 
         </Bundle-SymbolicName> 
         <Import-Package> 
          *,!com.google.gson 
         </Import-Package> 
         <Embed-Dependency>gson</Embed-Dependency> 
         <Export-Package> 
          org.apache.http.HttpEntity 
         </Export-Package> 
         <Web-ContextPath>${web.context}</Web-ContextPath> 
        </instructions> 
       </configuration> 
      </plugin> 
.................. 

錯誤消息:

java.lang.IllegalStateException: Can't install feature test/0.0.0: 
Could not start bundle mvn:ttt/test/1.0-SNAPSHOT in feature(s) test-1.0-SNAPSHOT: Unresolved constraint in bundle ttt.test [234]: Unable to resolve 234.0: missing requirement [234.0] osgi.wiring.package; (osgi.wiring.package=org.apache.http)

我想有在 「構築」 一些錯誤,但我沒有任何想法來解決。

回答

0

我想這個問題與osgi有關,你的osgi容器是基於Karaf的(因爲你正在談論'特性')。

它與您的包的構建無關:您還應該在容器中部署所需的運行時依賴項(karaf):在功能測試中,爲您在運行時需要的每個包添加<bundle>標記(使用dependency = true ),或者添加一個依賴到一個已經安裝了這些bundle的功能。此外,您不應該導出包org.apache.http.HttpEntity:它不是一個包,而是一個類,包「org.apache.http」由另一個包提供。

-1

您需要安裝HTTP客戶端包或把它放在你的feature.xml文件,如果你正在kar文件

bundle:install mvn:org.apache.httpcomponents/httpclient-osgi/4.5.1 
+0

這可能是正確答案,但請添加更多細節以進一步闡明它。 –

0
更好

的建議是使用HttpClient的,而不是HttpClient的OSGi的,因爲HttpClient的-OSGi是一個捆綁,這意味着在你的包開始之前,你需要啓動httpclient-osgi,它會帶來一些問題(你還需要把httpclient-osgi放入特性中)。如果你的函數只是使用一個http客戶端,使用httpclient就足夠了。只要在源代碼中依賴就行了〜

相關問題