繁体   English   中英

Maven + Tycho,添加了Maven依赖项

[英]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-plugincopy-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.MFBundle-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.coreorg.eclipse.team.svn.ui不能通过标准的Eclipse更新站点获得。

也许你可以尝试这个来解决这类问题:

  1. 依赖关系中 ,找到自动化依赖关系管理框。
  2. 使用Add添加想要的插件...
  3. 选择分析代码并通过以下方式将依赖项添加到MANIFEST.MF: Import-Package
  4. 单击“ 添加依赖项”,以便在附近的“ 导入的包 ”框中找到所需的包。

然后你可以运行Maven构建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM