2011-06-24 25 views
0

我有一個構建良好的Maven項目,我試圖添加對twitter4j的引用。使用maven-bundle-plugin的錯誤Embed-Dependency

所以我將其添加到POM:

<dependency> 
     <groupId>org.twitter4j</groupId> 
     <artifactId>twitter4j-core</artifactId> 
     <version>[2.2,)</version> 
     <type>jar</type> 
     <optional>false</optional> 
     <scope>compile</scope> 
    </dependency> 

當我建(MVN全新安裝),我得到:

[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [twitter4j] by class(es) on the Bundle-Classpath[Jar:dot]: [net/stevex/tweetfetcher/impl/TweetFetcherImpl.class] 

這是有道理的。該twitter4j包未嵌入捆綁。所以,我想補充一個嵌入的依賴於Maven的捆插件的說明:

<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 

,現在當我建,我得到:

[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [dalvik.system, javax.crypto, javax.crypto.spec, javax.management, javax.management.openmbean, org.apache.commons.logging, org.apache.log4j, org.slf4j.impl, twitter4j.internal.http.alternative] by class(es) on the Bundle-Classpath[Jar:dot, Jar:twitter4j-core-2.2.3.jar]: [twitter4j/internal/logging/CommonsLoggingLogger.class, twitter4j/internal/logging/Log4JLoggerFactory.class, twitter4j/auth/OAuthToken.class, twitter4j/internal/http/HttpClientFactory.class, twitter4j/auth/OAuthAuthorization.class, twitter4j/internal/logging/Log4JLogger.class, twitter4j/conf/ConfigurationBase.class, twitter4j/TwitterAPIMonitor.class, twitter4j/internal/logging/CommonsLoggingLoggerFactory.class, twitter4j/management/APIStatisticsOpenMBean.class, twitter4j/internal/logging/Logger.class] 

我不明白爲什麼twitter4j類失蹤,我不明白對dalvik.system,javax.crypto等的引用。這裏有什麼問題?

回答

3

問題是twitter4j項目需要錯誤列表中列出的所有軟件包。當你使用它時不包括所有的傳遞依賴。這裏是行家束-插件的嵌入傳遞指令將嵌入所有傳遞依賴

<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
<Embed-Transitive>true</Embed-Transitive> 

然而,這種失敗的OSGi的目的。這讓您知道兩個選項:

  1. 搜索SpringSource EBR中的第二個包。您只需在搜索框中輸入包名稱,結果將包括您的POM文件的xml。 SpringSource捆綁包將包含對EBR中其他捆綁包的引用,從而消除傳遞依賴關係的問題。

  2. 使用maven-bundle-plugin的bundle-all目標。這個目標將爲您的項目的每個依賴項運行maven bundle插件,並將結果綁定到您的目標目錄中。然後,您可以將這些軟件包安裝到本地存儲庫中。

我會推薦使用選項1作爲許多捆綁軟件,因爲您可以找到,然後在SpringSource沒有它們時默認選項2。

+1

twitter4j尋找的包不是必需的,所以我將import語句添加到Import-Package中,並將它們標記爲可選:twitter4j.internal.http.alternative; resolution:= optional(etc)。 – stevex