Maven类路径顺序问题 [英] Maven classpath order issues

查看:75
本文介绍了Maven类路径顺序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在Maven2中设置特定类路径顺序的方法,而不是我目前似乎遇到的随机顺序的方法吗?

Does anyone know of a way to set a specific classpath order in Maven2, rather than the random ordering I appear to experience at the moment?

有很多正当的理由想要这样做:

There are a number of legitimate reasons for wanting to do this:

  • 供应商提供了一个修补程序jar,其中包含先前发布的jar的重写类,因此,修补程序jar必须在类路径顺序中首先出现.
  • 在类路径上通过遍历pom依赖关系发现的两个jar包含同一包中具有相同符号的同一类.例如:

jboss jbossall-client 4.2.0.GA

jboss jbossall-client 4.2.0.GA

休眠 冬眠的 3.1

org.hibernate hibernate 3.1

都包含: org.hibernate.util.ReflectHelper.class,但是jbossall-client版本缺少getFastClass方法.

both contain: org.hibernate.util.ReflectHelper.class, but the jbossall-client version is missing the getFastClass method.

通过谷歌搜索,我发现这也许是Maven爱好者和面临此特定问题的人们之间的争论点,但是肯定有合理的理由对类路径进行排序.

From googling I see that this is perhaps a point of contention between maven enthusiasts and people facing this particular issue, but surely there are legitimate reasons for classpath ordering.

任何解决此难题的人的建议都将不胜感激!

Any advice from anyone that has solved this particular quandary would be much appreciated!

谢谢

推荐答案

从2.0.9版开始,maven将pom顺序用于类路径,因此您现在就可以对其进行实际操作了.我们主要是禁止传递传递性对外部库的依赖,这些外部库也直接包含在内.

As of version 2.0.9 maven uses pom order for classpath, so you can actually manipulate it now. We mostly supress transitive dependencies to external libraries that we also include directly.

从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类路径顺序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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