Sumod
Sumod

Reputation: 3846

Unable to run testng from command line

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 -

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.

Upvotes: 4

Views: 9436

Answers (6)

manpreta
manpreta

Reputation: 1

Add jcommander.jar in D:\testng and run this command:

java -cp "D:\testng\*" org.testng.TestNG testng.xml

Upvotes: 0

syed
syed

Reputation: 1

adding JCommander to the classpath solves the issue.

Upvotes: 0

dimo414
dimo414

Reputation: 48794

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.

Upvotes: 1

xtao
xtao

Reputation: 31

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.

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

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

Upvotes: 2

Sumod
Sumod

Reputation: 3846

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

Upvotes: -2

gadget
gadget

Reputation: 1978

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.

Upvotes: 2

Related Questions