I'm trying to run a very simple test using TestNG, but I'm getting this error message. I tried reading the previous answers, but it is not working to me. I would be happy if someone could help me out, since I'm just a beginner in TestNG. This is the error message :
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.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
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)
... 7 more
Yes there is an issue with testNG
running on eclipse. As of this post you can try a workaround to fix your error by adding the jcommander jar file in your build path and then run your testNG
suite from eclipse.
If you want to run using command prompt or terminal, here's how to do it on MAC -
java -cp "PATH/TO/TESTNG.jar:PATH/TO/jcommander-1.7.jar" org.testng.TestNG testng.xml
Similarly replace your path for windows too and your test suite will run as without any errors using command prompt.
See https://github.com/cbeust/testng-eclipse/issues/140.
Add jcommdar.jar to classpath and then run:
java -cp "C:\TestNG\testng.jar;C:\TestNG\jcommander.jar" org.testng.TestNG testng.xml
To overcome from this problem, we need to download the jcommander1.7 jar file.
to download the jar file visit below url and get jcommander1.7 jar file
http://www.java2s.com/Code/Jar/j/Downloadjcommander17jar.htm
Process to implement jcommander1.7 jar file-
Right click on the project->Properties->click on the liabraries->click on the Add external jars->navigate to the location where jcommander1.7 jar file is downloaded.
and run your script, now your script will run successfully.
Add jcommdar.jar
to classpath
and then run:
java -cp "C:\TestNG\testng.jar;C:\TestNG\jcommander.jar" org.testng.TestNG testng.xml
It is really helped for me.
I had the similar error while running my testng.xml. I replaced my selenium server jar which was included(build path) by a local user from his local path. Copy the jar files to the project folder(lib) and include them in your project. This worked for me.
I got this issue, after uninstalling my java jdk newer version and upgrading to java jdk older version.
I have resolved it, by recreating my java project in eclipse.