maven-2 - Maven : Multiple class with the same path implemented in different jar

标签 maven-2 dependencies

我遇到了多个类具有相同路径(即相同名称、相同包!!!)的问题。 由于某种原因,gwt-dev 附带了自己的 org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 和 javax.xml.parsers.DocumentBuilderFactory 版本。

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

有趣的是,eclipse 可以毫无问题地运行相同的代码(这是一个单元测试),但 Surefire 却不能。所以我猜问题是由于每个运行者考虑每个 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,您的应用程序就会从中选择类。

摘自maven 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-2 - Maven : Multiple class with the same path implemented in different jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612734/

相关文章:

eclipse - 将使用 Maven 生成的项目导入 Eclipse Indigo 时出现问题

gradle - 如何互相做gradle依赖项目

java - ivy 解决动态依赖

php - 何时使用 Facades 何时注入(inject)依赖

c++ - 使用maven2构建基于autotools的C/C++包

maven-2 - 如何阻止 Maven 在所有远程存储库中查找已安装到本地存储库的依赖项的 pom 文件?

java - 从 maven 程序集描述符中的 jars 中排除包

java - Maven exec 插件-当 classpathscope=test 时如何从 main/java 导入类

grails - 为什么 Grails 一直要求我 'upgrade' 到较低的插件版本?

c# - 如果程序集在 GAC 中,它调用的所有程序集是否也必须在 GAC 中?