Could not start testng from command line

I can run testng perfectly within Eclipse. However, I want to run it using the command line (Win 8), as described in various forums. Here are the different things I try with errors -

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.

+4
source share
5 answers

The bug was fixed using the surefire plugin to run TestNG tests using the "mvn package" command and resolving all dependency on external jars.

-1
source

I assume that you are using a jar that does not contain dependencies, such as JCommander (perhaps the one that was created for use with Maven). Try using a jar of zip .

+2

testng.jar, , testng.jar JCommander, . , .

java -cp "D:\testng\testng-6.8.7.jar": " Jarander jar" org.testng.TestNG testng.xml // ,

- testng, jcommander .

+2

, JCommander . "", Jar.

+1

JCommander .

0
source

All Articles