简体   繁体   中英

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. I have used maven assembly plugin. The jar is getting created but when I try to run the jar using

 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

<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.

like this:

 <project> <groupId>com.rohan</groupId> <artifactId>jmetertester</artifactId> **<packaging>jar</packaging>**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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