maven java版本管理_Maven依赖版本控制和java.lang.NoClassDefFoundError

我有一个Java项目X在项目Y上有依赖关系(在pom文件中).

我在Y中修改并使用Maven工具构建X,Y然后在没有问题的情况下运行X(在JBoss上).

当我在Y中添加新类然后使用Maven构建(没有问题),然后运行X时,它会为新类抛出java.lang.NoClassDefFoundError.

我认为它是一个Maven依赖版本或类似的东西……我主要搜索谷歌,但没有任何影响…如何解决这个问题?

解决方法:

Moro,你在评论中写道,X声明了以下依赖:

Y

Y

provided

1.0

第一点.你在这里使用的是“固定”版本(而不是“SNAPSHOT”).使用SNAPSHOT时,maven会在每次构建时自动获取最新的SNAPSHOT.另一方面,当你使用1.0时,一旦maven下载了这个工件,它就永远不会尝试获得新的1.0.所以,你应该增加Y的版本,或者,如果Y正在积极开发(增强,错误修复等),你应该真的使用SNAPSHOT.

有关SNAPSHOT的更多信息,请查看Sonatype的书中的第9.3.1.2. SNAPSHOT Versions章:

Why would you use this? SNAPSHOT

versions are used for projects under

active development. If your project

depends on a software component that

is under active development, you can

depend on a SNAPSHOT release, and

Maven will periodically attempt to

download the latest snapshot from a

repository when you run a build.

Similarly, if the next release of your

system is going to have a version

“1.4”, your project would have a

version “1.4-SNAPSHOT” until it was

formally released.

provided dependencies are used when

you expect the JDK or a container to

provide them. For example, if you were

developing a web application, you

would need the Servlet API available

on the compile classpath to compile a

servlet, but you wouldn’t want to

include the Servlet API in the

packaged WAR; the Servlet API JAR is

supplied by your application server or

servlet container. provided

dependencies are available on the

compilation classpath (not runtime).

They are not transitive, nor are they

packaged.

这真的是你想要的吗?你是如何在JBoss上部署X和Y的?你不应该使用默认的编译范围吗?

标签:java,maven-2,maven-plugin

来源: https://codeday.me/bug/20190527/1160117.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值