[英]Jar created using maven-assembly-plugin not running with mvn install
I am creating a jar file using maven assembly plugin.我正在使用 maven 程序集插件创建 jar 文件。 The minimal pom file looks like:
最小的 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>
When I run mvn clean install
, it creates a jar file but when I run the jar file using java -jar <jarfileName>
, it says Error: Could not find or load main class
. When I run
mvn clean install
, it creates a jar file but when I run the jar file using java -jar <jarfileName>
, it says Error: Could not find or load main class
. While if I edit the above pom, to have虽然如果我编辑上面的 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>
and after running mvn clean install
, I run mvn compile test-compile assembly-plugin
, it generates the same jar file, but this jar file runs as expected.在运行
mvn clean install
之后,我运行mvn compile test-compile assembly-plugin
,它生成相同的 jar 文件,但是这个 jar 文件按预期运行。 So, my question is why the jar file with the first approach does not runs and what exactly does mvn compile test-compile assembly-plugin
command do?所以,我的问题是为什么第一种方法的 jar 文件不能运行,
mvn compile test-compile assembly-plugin
命令究竟是做什么的?
I was facing Same issue,我面临同样的问题,
please check if you have added jar at top you pom.xml inside tag.请检查您是否在 pom.xml 顶部添加了 jar 内部标签。
like this:像这样:
<project>
<groupId>com.rohan</groupId>
<artifactId>jmetertester</artifactId>
**<packaging>jar</packaging>**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.