【问题标题】:How to run multi module maven application? [duplicate]如何运行多模块 Maven 应用程序? [复制]
【发布时间】:2020-05-22 03:21:54
【问题描述】:

我尝试运行我的多模块 maven 应用程序

mvn -f pom.xml -DskipTests clean install
java -jar modules/mainmodule/target/mainmodule-1.0-SNAPSHOT.jar

构建工作没有问题,所有模块都可以在我的 .m2 存储库中使用,但是在运行应用程序时出现错误:

Exception in thread "main" java.lang.NoClassDefFoundError: de/peyrer/indexmodule/Indexmodule

这不是 java 找不到的唯一依赖项,它找不到任何依赖项。 对我来说,java 似乎找不到我的本地 maven 存储库。那我做错了什么?

【问题讨论】:

  • 在 jar 中没有包含依赖项。仅当您明确并通过 maven-assembly-plugin/maven-shade-plugin 创建一个称为 ueber-jar 或可执行 jar ...

标签: java maven module dependencies maven-module


【解决方案1】:

NoClassDefFoundError 错误发生在执行代码时应用程序所依赖的类不可用。

这可能是因为您没有将 maven 项目的依赖项添加到 jar 文件中。

尝试使用 maven-assembly-plugin。

  <build>
    <plugins>
      <!-- any other plugins -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 2019-03-04
    • 1970-01-01
    相关资源
    最近更新 更多