Maven + Tycho,添加Maven依赖关系 [英] Maven + Tycho, adding Maven dependencies

查看:613
本文介绍了Maven + Tycho,添加Maven依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Maven和Tycho构建的Eclipse插件。目前,
但是,我们仍然通过一批手动
添加的JAR文件而不是由Maven提供所有项目依赖关系。这是由于以下原因:(1)
依赖关系不能通过标准的Eclipse更新站点(至少
不在当前版本中),(2)依赖关系不可用作捆绑



这些依赖关系的最大部分是Selenium库(API,Remote,
特定于浏览器的libs及其传递性依赖关系,如Guava等。 )



我浪费了几个小时,试图在我们的Maven构建过程中拉出这些依赖关系。
遵循这个问题,我尝试过 p2-maven-plugin ,我创建了一个更新
网站,其中添加了我的依赖关系,我添加到我的Eclipse目标平台。然而,在运行时
,在不同JAR之间引用的类不能是
加载(我认为,从我非常有限的OSGi知识,因为$ $ $ $ $ $ $ $ $ $ $ $ $ code> MANIFEST.MF 文件)。这是一个例子
的问题,当尝试创建一个 RemoteWebDriver ,它使用
DesiredCapabilities class(两个类在不同的包中):

 线程中的异常Thread-8java.lang.NoClassDefFoundError:org / openqa / selenium / remote / DesiredCapabilities 
在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:243)
在org.openqa.selenium.remote.RemoteWebDriver。< init> (RemoteWebDriver.java:126)
在org.openqa.selenium.remote.RemoteWebDriver。< init>(RemoteWebDriver.java:153)
...
导致:java.lang.ClassNotFoundException :org.openqa.selenium.remote.DesiredCapabilities无法通过org.seleniumhq.selenium.remote-driver_2.45.0
在org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)找到。
在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
在org.eclipse.osgi .internal.loader.BundleLoader.findClass(BundleLoader.java:344)
在org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
在java.lang.ClassLoader .loadClass(ClassLoader.java:357)
... 7更多

有什么吗当使用 p2-maven-plugin 时,我还是需要照顾? pom.xml 的相关部分如下所示:

  ;插件> 
< groupId> org.reficio< / groupId>
< artifactId> p2-maven-plugin< / artifactId>
< version> 1.1.1-SNAPSHOT< / version>
<执行>
< execution>
< id> default-cli< / id>
< configuration>
<工件>
< 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 阶段来拉取所有必要的依赖关系(与我的初始感觉相反,这可以与 pom.xml 结合使用 eclipse-plugin 包装和清单第一方法)。相关部分如下所示:

 < build> 
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-dependency-plugin< / artifactId>
< version> 2.10< / version>
<执行>
< execution>
< id> copy-dependencies< / id>
< phase> initialize< / phase>
< goals>
< goal> copy-dependencies< / goal>
< / goals>
< configuration>
< includeScope>运行时< / includeScope>
< / configuration>
< / execution>
< / executions>
< / plugin>
< / plugins>
< / build>

然后将Maven依赖项复制到 target / dependency



只有一点问题: MANIFEST.MF中的 Bundle-ClassPath 需要手动更新,以防在更新Maven依赖项时更改JAR文件的名称(例如 commons-io-2.4.jar 成为 commons-io-2.5.jar )。



到最后一句:可以通过以下选项方便地剥离版本号:< stripVersion> true< / stripVersion> 。这意味着,上述库将被重命名为 commons-io.jar ,因此当版本号更改时,不需要更新路径。


We have an Eclipse Plugin which we build using Maven and Tycho. Currently however, we still provide all project dependencies through a bunch of manually added JAR files and not by Maven. This is due to the following reasons: (1) The dependencies are not available through a standard Eclipse update site (at least not in a current version), (2) the dependencies are not available as bundles.

The biggest part of these dependencies are the Selenium libraries (API, Remote, browser-specific libs and their transitive dependencies, such as Guava, etc.)

I've wasted hours, trying to pull those dependencies during our Maven build. Following this SO question, I tried the p2-maven-plugin, created an update site with our dependencies which I added to my Eclipse target platform. However, during runtime, classes, which are referenced across different JARs could not be loaded (I assume, from my very limited OSGi knowledge, because some necessary information was missing in the MANIFEST.MF files). Here's an example of the issue, when trying to create a RemoteWebDriver, which uses the DesiredCapabilities class (both classes in different bundles):

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

Is there anything I still need to take care of, when using the p2-maven-plugin? The relevant parts of the pom.xml looked like this:

<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>

解决方案

Couldn't get it to work, so we're now using the maven-dependency-plugin with the copy-dependencies, which we execute during the Maven initialize phase to pull all necessary dependencies (contrary to my initial feeling, this can be combined with the pom.xml using the eclipse-plugin packaging and the "manifest first" approach). The relevant part looks like this:

<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>

The Maven dependencies are then copied to target/dependency.

Only little issue: The Bundle-ClassPath in the MANIFEST.MF needs to be manually updated in case the name of a JAR file changes when updating Maven dependencies (e.g. commons-io-2.4.jar becomes commons-io-2.5.jar).

[edit] Revisiting this answer in regards to the last sentence above: The version numbers can be conveniently stripped through the following option: <stripVersion>true</stripVersion>. This means, the above library will be renamed to commons-io.jar and thus no paths need to be updated when a version number changes.

这篇关于Maven + Tycho,添加Maven依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆