使用 maven-assembly-plugin 创建的 Jar 未与 mvn install 一起运行

问题描述

我正在使用 Maven 程序集插件创建一个 jar 文件。 最小的 pom 文件看起来像:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.org.taptest.tests.TestsRunningAsTAP</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/target/</outputDirectory>
        </configuration>
      </execution>
   </executions>
</plugin>

当我运行 mvn clean install 时,它会创建一个 jar 文件,但是当我使用 java -jar <jarfileName> 运行 jar 文件时,它会显示 Error: Could not find or load main class。 而如果我编辑上面的pom,有

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.3.0</version>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
                          
       <mainClass>com.org.taptest.tests.TestsRunningAsTAP</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
       <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>

在运行 mvn clean install 后,我运行 mvn compile test-compile assembly-plugin,它生成相同的 jar 文件,但此 jar 文件按预期运行。 所以,我的问题是为什么第一种方法的 jar 文件不运行,mvn compile test-compile assembly-plugin 命令究竟做了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)