简体   繁体   English

使用 maven 程序集插件创建 jar 时出错

[英]Getting error while creating jar using maven assembly plugin

I am trying to create a jar, that contains some test classes and a main class that runs those test classes using custom junit runner.我正在尝试创建一个 jar,其中包含一些测试类和一个使用自定义 junit 运行器运行这些测试类的主要 class。 I have used maven assembly plugin.我使用了 maven 组装插件。 The jar is getting created but when I try to run the jar using jar 正在创建,但是当我尝试使用 jar

 java -jar <nameofthejar>

it gives error saying:它给出了错误说:

 Error: Could not find or load main class com.ora.arb.tap.Main

Here is my project structure:这是我的项目结构:

 src: - main: - java: - resources: - test: - java: - tap: - Main - TestClass1 - TestClass2 - resources:

assembly plugin from pom.xml来自 pom.xml 的汇编插件

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4.1</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.ora.arb.tap.Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>attached</goal> </goals> <configuration> <outputDirectory>${basedir}/target/tap</outputDirectory> </configuration> </execution> </executions> </plugin>

Whats the issue and how can I fix it?什么问题,我该如何解决?

I was facing Same issue,我面临同样的问题,

please check if you have added packaging jar at top your 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM