简体   繁体   English

Maven项目中创建可执行jar时出错

[英]error in creating executable jar in a Maven Project

I have created a maven project and writing tests in it using testng. 我创建了一个maven项目,并使用testng在其中编写测试。 I have also created an executable jar using mvn package command but getting error when executing it. 我还使用mvn package命令创建了一个可执行jar,但是执行它时出错。 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 这是我的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. 我是Maven的新手,并且从各个地方复制了pom.xml的某些内容(特别是)。请让我知道是否有多余的数据或标记。 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 . 您的类的名称是apitesting1.apitesting1.App ,而不是src/main/java/apitesting1.apitesting1.App.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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