本文介绍了Maven的。传递依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目P取决于依赖关系A.依赖关系B.我的项目的pom.xml文件包含A作为依赖,它的jar包含在P的类路径中。但是,在P的运行时抛出一个 NoClassDefFoundError ,这是由于缺少B jar。



不应该Maven已经自动下载了这些依赖关系?

解决方案

除非B是的maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependenciesrel =noreferrer> P具有compile(*)范围(参见并阅读注释),因此应该在运行时可用。

由于您在Eclipse下运行该项目,所以类路径是为您设置的,所以我'将排除此级别的错误。这使我们有可选的依赖关系。



PS:调查这种问题的一个非常有用的工具是依赖:tree


My project P depends on dependency A which depends on dependency B. My project's pom.xml file includes A as a dependency, and its jar is included in P's classpath. However, there is a NoClassDefFoundError thrown at runtime of P, which stems from missing B jars.

Shouldn't Maven have downloaded these dependencies automatically?

解决方案

Unless B is an optional dependency of A, B should be a dependency of P with a "compile(*)" scope (see the table of Dependency Scope and read the note) and should thus be available at runtime.

Since you're running the project under Eclipse, the class path is setup for you so I'll exclude a mistake at this level. This leaves us with the case of the optional dependency.

PS: A very useful tool to investigate this kind of problem is dependency:tree.

这篇关于Maven的。传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:19
查看更多