Reputation: 10570
I have added a jar to my class path like:
export CLASSPATH="/Users/myname/.m2/repository/org/testng/testng/7.3.0/testng-7.3.0.jar";
and when I echo it, I get that jar.
However, I am running my jar like:
java -cp target/TestNgExample-1.0-SNAPSHOT.jar:myname org.testng.TestNG testng.xml
but I get:
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
So as you see, I added that jar to the class path but still unable to use it.
Any help?
Upvotes: 0
Views: 1707
Reputation:
First: The use of the CLASSPATH
environment variables is strong discouraged.
However, as documented in the manual providing the -cp
(or --class-path
) parameter on the command line overrides the CLASSPATH content
Specifying classpath overrides any setting of the CLASSPATH environment variable. If the class path option isn't used and classpath isn't set, then the user class path consists of the current directory (.).
To include the TestNG jar file into your classpath, include it in the -cp parameter:
java -cp target/TestNgExample-1.0-SNAPSHOT.jar:/Users/myname/.m2/repository/org/testng/testng/7.3.0/testng-7.3.0.jar org.testng.TestNG testng.xml
Upvotes: 3