如何知道哪个项目类路径具有特定jar的引用。实际上我使用的一个类是有多个版本的jar,因此在运行时给出问题。我只想从相应项目的类路径中删除以前的版本。
每个项目中都有很多项目和Jars,所以我不想打开每个项目Build Path并查找Jar。有没有捷径。
答案 0 :(得分:2)
基于对评论的澄清。打开pom.xml
文件。并导航到dependency heirarchy
标签。这将显示项目的所有依赖项。
当您看到重复的jar文件(作为传递依赖项的一部分下载)时,您可以选择。
从pom.xml
或
右键单击jar(传递)并选择exclude。
您也可以通过命令行检查依赖关系树。
例如,要找出Maven Dependency Plugin正在使用Commons Collections 2.0的原因,我们可以在项目目录中执行以下命令:
mvn dependency:tree -Dverbose -Dincludes=commons-collections
官方网页上显示的一个非常好的示例,说明了使用依赖树解决冲突
例如,要找出Maven Dependency Plugin正在使用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.
答案 1 :(得分:0)
只需在所有.classpath文件中搜索该先前版本。
为您的Maven项目执行依赖关系:树并获取依赖关系树。在这棵树上搜索你的罐子。