Maven:具有相同路径的多个类在不同的jar中实现 [英] Maven: Multiple class with the same path implemented in different jar

查看:49
本文介绍了Maven:具有相同路径的多个类在不同的jar中实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了多个具有相同路径的类(即相同的名称,相同的包!!!).出于某种原因,gwt-dev 带有自己的 org.apache.xerces.jaxp.DocumentBuilderFactoryImpljavax.xml.parsers.DocumentBuilderFactory 版本.

I'm running into trouble with having multiple class with the same path (i.e. same name, same package!!!). For some reason, gwt-dev comes with its own version of org.apache.xerces.jaxp.DocumentBuilderFactoryImpl and javax.xml.parsers.DocumentBuilderFactory.

同时,spring 也依赖于这些类,但来自不同的 jar.我不知道应该是什么,但看起来像 xalan &xml-api是spring依赖的两个依赖(这些依赖是可选的)

At the same time, spring also depends on these classes but from different jar. I don't know what should be, but look like xalan & xml-api are the two dependencies that spring depends on (these dependency are optional)

有趣的是,eclipse 可以毫无问题地运行相同的代码(这是一个单元测试),但 surefire 不能.所以我猜这个问题是由于每个跑步者考虑每个罐子的优先级的方式.

Funny thing is that eclipse can run the same code (it's a unit test) without problem, but surefire cannot. So I guess the problem is due to the way each runner consider the priority of each jar.

现在来个问题:我如何设置我的 POM,以便我可以确保当任何代码在我的应用程序中运行时,一个 jar 中的类将被选择而不是其他 jar 中的类?

Now come to the question: How can I setup my POM so that I can sure that when ever any code running inside my app, then class from a jar will be selected over class from other jar?

谢谢.

推荐答案

现在来个问题:我如何设置我的 POM,以便我可以确保当任何代码在我的应用程序中运行时,一个 jar 中的类将被选择而不是其他 jar 中的类?

Now come to the question: How can I setup my POM so that I can sure that when ever any code running inside my app, then class from a jar will be selected over class from other jar?

从 Maven 2.0.9 开始,Maven 使用 POM 中的依赖顺序来构建类路径,以便您可以对其进行操作.只需先声明正确"的 jar,您的应用就会从中选择类.

Since Maven 2.0.9, Maven uses the order of dependencies in the POM to build the classpath so you can manipulate it. Just declare the "right" jar first and your app will pick the class from it.

来自 maven 2.0.9 的发行说明:

From the release notes of maven 2.0.9:

MNG-1412/MNG-3111 引入了类路径上依赖项的确定性排序.过去,使用自然集排序,这会导致奇怪的结果.现在从您的 pom 中保留了顺序,最后添加了由继承添加的依赖项.在具有冲突或重复依赖项的构建中,这可能会导致输出发生更改.简而言之,如果您对 2.0.9 有奇怪的问题,请查看依赖项,看看您是否在某处有冲突.

MNG-1412 / MNG-3111 introduced deterministic ordering of dependencies on the classpath. In the past, natural set ordering was used and this lead to odd results. The ordering is now preserved from your pom, with dependencies added by inheritence added last. In builds that had conflicting or duplicate dependencies, this may introduce a change to the output. In short, if you have weird issues with 2.0.9, take a look at the dependencies to see if you have conflicts somewhere.

这篇关于Maven:具有相同路径的多个类在不同的jar中实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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