
通常,当您在编译时拥有该类但在运行时不存在该类时,便会出现NoClassDef错误。请彻底检查您的Maven依赖项是否存在任何jar冲突。这可能是NoClassDef的可能原因。检查pom.xml并导航到“依赖关系层次结构”选项卡,以验证是否两次都看不到相同的jar,但版本不同。
如果确实有jar冲突,则必须根据使用特定版本的要求删除其中之一
您也可以通过命令行检查依赖关系树。
例如,要了解为什么Maven依赖插件使用Commons Collections 2.0,我们可以在项目目录中执行以下命令:
mvn dependency:tree -Dverbose -Dincludes=commons-collections
这是官方的Maven依赖插件
编辑:直接从Maven依赖插件页面。我认为这将使答案更具描述性,而不是单击几个链接。官方页面上显示的一个很好的例子,说明了如何使用依赖树来解决冲突
例如,要了解为什么Maven依赖插件使用Commons Collections 2.0,我们可以在项目目录中执行以下命令:
mvn dependency:tree -Dverbose -Dincludes=commons-collectionsThe 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.prehaus.plexus:plexus-velocity:jar:1.1.3:compile[INFO] - commons-collections:commons-collections:jar:2.0:compileThus 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.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)