且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何在Maven中使用其他项目中的类? (引发ClassNotFoundException和NoClassDefFoundError)

更新时间:2023-09-24 23:21:10

您可以尝试删除< packaging> war< / packaging> ? Maven的默认包装为 jar ,这就是您需要B的条件。

can u try to remove <packaging>war</packaging> from B? Maven's default packaging is jar, and this is what you need for B.

此外,将B添加到依存关系。


  • 构建B项目。使用 mvn全新安装,它将在您的本地存储库(.m2)中安装B的
    JAR + POM。

  • 验证它是否存在...然后
    Maven将能够找到它,所以您将不会收到错误消息可能
    找不到工件de.qufis :CentwertApp

  • Build A。

  • Build B project. use mvn clean install, that would install B's JAR+POM in your local repository (.m2).
  • Verify it is there... Then Maven will be able to find it, so you will not get the error "Could not find artifact de.qufis:CentwertApp"
  • Build A.

通常,依赖项的类型为JAR。如果B 必须为WAR,请参见

Usually, dependencies are of type JAR. If B must be a WAR, see this.