2

I am following this tutorial http://www.tutorialspoint.com/testng/testng_environment.htm

When I enter the command:

java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml 

I get the error below:

Error: Could not find or load main class org.testng.TestNG 

Anyone know why? much appreciated.

1
  • Tag java is very generic. If you use more specific tags (TestNg in this case), you will have much chance to get it answered Commented Mar 5, 2015 at 22:48

5 Answers 5

2

I encountered exactly the same issue, using the same tutorial today. I was happy to discover I was not alone having the same problem! Anyway, I tried the solution posted on this other post and it worked for me: could not find or load main class org.testng.TestNG

In other word, the working command line for me is:

java -cp ".;C:\TestNG\testng-6.8.jar" org.testng.TestNG testng.xml 

Hope this will help you!

Sign up to request clarification or add additional context in comments.

3 Comments

my command was java -cp ".;C:\TestNG\testng-6.8.jar" org.testng.TestNG testng.xml
the CLASSPATH and TESTNG_HOME were set under system variables or User variable?
I have my both variables under the System variables. Not only I added %TESTNG_HOME%\testng-6.8.jar to the CLASSPATH but also to the PATH variable. Not sure this is the reason why it works for me but in case it can be...
1

It seems to be issue with JUnit dependency/jars. Change your junit version to 3.8.1 and build your workspace, it will work

Comments

0

Add testng-<version>.jar to the -cp argument.

Comments

0

Two ways are available to solve above problem.In Below mentioned answers change path according to your setup.Before executing the below command in command prompt make sure all selenium jars and TestNG jars should be in the lib folder.

First way: java -cp C:\Users\urscomputer\workspace\JenkinsIntegration\lib*;C:\Users\urscomputer\workspace\JenkinsIntegration\bin; org.testng.TestNG testng.xml

Second way:(Provide space between set and classpath)

  1. set classpath=C:\Users\urscomputer\workspace\JenkinsIntegration\lib*;C:\Users\urscomputer\workspace\JenkinsIntegration\bin;
  2. java org.testng.TestNG testng.xml

Comments

0

I have been working on Ubuntu 15.04 and faced a similar problem. I used maven to install testng. The advantage was it installed all the dependencies along with it. If you are not using maven, then along with testng jar, download jcommander and beanshell jar files as well.

When executing the class files after compilation provide the classpath of the following:

  1. testng jar
  2. jCommander jar
  3. beanshell jar

This is the command I used on my system to run the same example code as mentioned on TutorialsPoint:

java -cp /home/phantom/TestNg\ tutorialsPoint/Programming1:/usr/share/maven-repo/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar:/usr/share/maven-repo/com/beust/jcommander/1.35/jcommander-1.35.jar:/usr/share/maven-repo/org/testng/testng/6.9.5-SNAPSHOT/testng-6.9.5-SNAPSHOT.jar org.testng.TestNG testng.xml 

Programming1 is the directory where my .java and .class files are stored.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.