无法从命令行运行testng

时间:2021-10-12 08:57:58

I am able to run testng perfectly fine from within Eclipse. However, I want to run it using command line (Win 8) as explained on different forums. Here are different things I am trying with the errors -

我可以在Eclipse中运行testng,完全没问题。但是,我想使用命令行(Win 8)运行它,在不同的论坛上有解释。这里有一些我正在尝试的错误-

1.
java -cp "D:\testng\testng-6.8.7.jar" org.testng.TestNG testng.xml
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/
ParameterException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterExcep
tion
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more
2. java -cp "D:\testng\testng-6.8.7.jar:{$PATH_TILL_HERE}\target\test-classes\org\test\automation\links\LinksTest.cl
ass" org.testng.TestNG testng.xml
Error: Could not find or load main class org.testng.TestNG

Thanks for any pointers.

感谢任何指针。

5 个解决方案

#1


2  

I guess you are using a jar that does not contain dependencies like JCommander (probably the one created to use with Maven). Try using the jar from this zip.

我猜您使用的jar不包含JCommander之类的依赖项(可能是创建来与Maven一起使用的jar)。尝试使用这个zip文件中的jar。

#2


2  

In your command line command you try to run testng.jar, unfortunately testng.jar uses JCommander and it is a dependency. It must also have the location of that jar as well to execute.

在命令行命令中,尝试运行testng。jar,不幸的是testng。jar使用j指挥官,它是一个依赖项。它还必须有jar的位置才能执行。

java -cp "D:\testng\testng-6.8.7.jar":"this should be replaced with the path to your Jcommander jar" org.testng.TestNG testng.xml //hopefully this works

java - cp“D:\ testng \ testng-6.8.7。jar:“应该用Jcommander jar的路径替换它”org.testng。TestNG TestNG。xml / /希望这工作

Someone should send a note to testng to put the jcommander code into their jar.

应该向testng发送一个通知,将jcommander代码放到他们的jar中。

#3


1  

Like the error suggests, you need to include JCommander in your classpath. You can follow the above link to the most recent version and click the "Artifact" link to download the Jar.

正如错误提示的那样,您需要在类路径中包含j指挥官。您可以按照上面的链接到最近的版本,然后点击“工件”链接来下载Jar。

#4


0  

adding JCommander to the classpath solves the issue.

向类路径添加JCommander可以解决这个问题。

#5


-1  

Fixed the issue by using surefire plugin to run TestNG tests using "mvn package" command and resolving all the dependency on external jars.

通过使用surefire插件使用“mvn package”命令运行TestNG测试并解决所有对外部jar的依赖,解决了这个问题。

#1


2  

I guess you are using a jar that does not contain dependencies like JCommander (probably the one created to use with Maven). Try using the jar from this zip.

我猜您使用的jar不包含JCommander之类的依赖项(可能是创建来与Maven一起使用的jar)。尝试使用这个zip文件中的jar。

#2


2  

In your command line command you try to run testng.jar, unfortunately testng.jar uses JCommander and it is a dependency. It must also have the location of that jar as well to execute.

在命令行命令中,尝试运行testng。jar,不幸的是testng。jar使用j指挥官,它是一个依赖项。它还必须有jar的位置才能执行。

java -cp "D:\testng\testng-6.8.7.jar":"this should be replaced with the path to your Jcommander jar" org.testng.TestNG testng.xml //hopefully this works

java - cp“D:\ testng \ testng-6.8.7。jar:“应该用Jcommander jar的路径替换它”org.testng。TestNG TestNG。xml / /希望这工作

Someone should send a note to testng to put the jcommander code into their jar.

应该向testng发送一个通知,将jcommander代码放到他们的jar中。

#3


1  

Like the error suggests, you need to include JCommander in your classpath. You can follow the above link to the most recent version and click the "Artifact" link to download the Jar.

正如错误提示的那样,您需要在类路径中包含j指挥官。您可以按照上面的链接到最近的版本,然后点击“工件”链接来下载Jar。

#4


0  

adding JCommander to the classpath solves the issue.

向类路径添加JCommander可以解决这个问题。

#5


-1  

Fixed the issue by using surefire plugin to run TestNG tests using "mvn package" command and resolving all the dependency on external jars.

通过使用surefire插件使用“mvn package”命令运行TestNG测试并解决所有对外部jar的依赖,解决了这个问题。