I have created a maven project and writing tests in it using testng. I have also created an executable jar using mvn package command but getting error when executing it. I could not actually figure out the error. Please help me with this.
$java -jar apitesting1-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/ITestListener
Caused by: java.lang.ClassNotFoundException: org.testng.ITestListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: apitesting1.apitesting1.App. Program will exit.
This is my main class
public class myClass
{
public static void main( String[] args )
{
}
}
This is my pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>abc</groupId>
<artifactId>abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions> <execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>abc.abc.myClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
I am new to Maven.. and copied some of the contents of pom.xml (specifically) from various places.. Please let me know if there is any redundant data or tag. I however feel that there is.. Please help.
Thanks :)
The main class element must contain the name of a class. The name of your class is apitesting1.apitesting1.App
, not src/main/java/apitesting1.apitesting1.App.java
.
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.