我有一个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