【问题标题】:Projects in Workspace having a jar on their Build PathWorkspace 中的项目在其构建路径上有一个 jar
【发布时间】:2014-01-18 13:36:52
【问题描述】:

如何知道哪个项目的 Class-path 有特定 jar 的引用。实际上,我正在使用的其中一个类存在于多个版本的 jar 中,因此在运行时会出现问题。我只想从各个项目的类路径中删除以前的版本。

每个项目中有很多项目和罐子,所以我不想打开每个项目的构建路径并寻找罐子。有什么捷径吗?

【问题讨论】:

  • 是时候使用 maven 了 :) 如果是,它会显示依赖层次结构。由于传递依赖,这将显示重复的 jars
  • 谢谢。是的,我正在使用 Maven。如何查看依赖层次结构。

标签: java eclipse


【解决方案1】:

基于对评论的澄清。打开pom.xml 文件。并导航到dependency heirarchy 选项卡。这将向您显示项目的所有依赖项。 当您确实看到重复的 jar 文件(作为传递依赖项的一部分下载)时,您可以选择。

  1. pom.xml 中删除您自己的依赖定义

  2. 右键单击 jar(传递)并选择排除。

您也可以通过命令行检查您的依赖关系树。

例如,要找出 Maven 依赖插件使用 Commons Collections 2.0 的原因,我们可以在项目目录中执行以下操作:

mvn dependency:tree -Dverbose -Dincludes=commons-collections

这里是官方Maven dependency plugin

编辑:直接来自 Maven 依赖插件页面。我认为这会使答案更具描述性,而不是单击多个链接。

官方页面上展示的关于解决冲突使用依赖树的一个很好的例子

例如,要找出 Maven 依赖插件使用 Commons Collections 2.0 的原因,我们可以在项目目录中执行以下操作:

mvn dependency:tree -Dverbose -Dincludes=commons-collections

The verbose flag instructs the dependency tree to display conflicting dependencies that were omitted from the resolved dependency tree. In this case, the goal outputs:

[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] |  \- commons-validator:commons-validator:jar:1.2.0:compile
[INFO] |     \- commons-digester:commons-digester:jar:1.6:compile
[INFO] |        \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.0)
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO]    \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO]       \- commons-collections:commons-collections:jar:2.0:compile
Thus we can see that Commons Collections 2.0 was chosen over 2.1 since it is nearer, and by default Maven resolves version conflicts with a nearest-wins strategy.

More specifically, in verbose mode the dependency tree shows dependencies that were omitted for: being a duplicate of another; conflicting with another's version and/or scope; and introducing a cycle into the dependency tree.

【讨论】:

  • 谢谢哥们。我几乎可以解决这个问题。感谢您的帮助。
【解决方案2】:

只需在所有 .classpath 文件中搜索该先前版本即可。

为您的 Maven 项目执行 Dependency:Tree 并获取依赖树。在这棵树中搜索你的罐子。

【讨论】:

    猜你喜欢
    • 2011-11-14
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2017-12-08
    相关资源
    最近更新 更多