[英]Maven + Tycho, adding Maven dependencies
我們有一個Eclipse插件,我們使用Maven和Tycho構建。 但是,目前我們仍然通過一堆手動添加的JAR文件而不是Maven提供所有項目依賴項。 這是由於以下原因:(1)依賴關系不能通過標准的Eclipse更新站點獲得(至少在當前版本中不可用),(2)依賴關系不能作為bundle使用。
這些依賴項中最大的部分是Selenium庫(API,遠程,特定於瀏覽器的庫及其傳遞依賴項,例如Guava等)。
我浪費了幾個小時,試圖在我們的Maven構建期間拉出這些依賴項。 在這個問題之后,我嘗試了p2-maven-plugin
,創建了一個帶有依賴關系的更新站點,我將其添加到Eclipse目標平台。 但是,在運行時,無法加載在不同JAR中引用的類(我假設,從我非常有限的OSGi知識,因為MANIFEST.MF
文件中缺少一些必要的信息)。 這是一個問題的例子,在嘗試創建一個使用DesiredCapabilities
類的RemoteWebDriver
(兩個類都在不同的包中):
Exception in thread "Thread-8" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/DesiredCapabilities
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:243)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
…
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.DesiredCapabilities cannot be found by org.seleniumhq.selenium.remote-driver_2.45.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
在使用p2-maven-plugin
時,還有什么我需要注意的嗎? pom.xml
的相關部分如下所示:
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.1-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact>
<id>org.seleniumhq.selenium:selenium-remote-driver:2.45.0</id>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
無法讓它工作,所以我們現在使用maven-dependency-plugin
和copy-dependencies
,我們在Maven initialize
階段執行它以獲取所有必要的依賴項(與我最初的感覺相反,這可以結合使用)使用eclipse-plugin
打包和“清單第一”方法使用pom.xml
。 相關部分如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>initialize</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
然后將Maven依賴項復制到target/dependency
。
只有少數問題:在更新Maven依賴項時,如果JAR文件的名稱發生變化,需要手動更新MANIFEST.MF
的Bundle-ClassPath
(例如, commons-io-2.4.jar
變為commons-io-2.5.jar
)。
[edit]關於上面的最后一句重新回答這個答案:可以通過以下選項方便地刪除版本號: <stripVersion>true</stripVersion>
。 這意味着,上面的庫將被重命名為commons-io.jar
,因此當版本號更改時不需要更新任何路徑。
另一種可能性
一些jar文件可能會被破壞(如果你正在使用Eclipse,它常見的是hibernate-commons-annotations-4.0.1.Final.jar;無效的LOC頭文件(錯誤的簽名)? )。 要檢查這種可能性,請嘗試手動打開jar以查看它是否正常。
我還使用Maven和Tycho構建了一個Eclipse插件。 我有同樣的問題:bundle org.eclipse.team.svn.core
和org.eclipse.team.svn.ui
不能通過標准的Eclipse更新站點獲得。
也許你可以嘗試這個來解決這類問題:
然后你可以運行Maven構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.