I packed test classes into JAR. I have junit-4.10.jar
and aJar.jar
in the same folder. When I try to execute:
java -cp .:junit-4.10.jar org.junit.runner.JUnitCore TestOne
Error: Could not find or load main class org.junit.runner.JUnitCore
How to make it work?
When I type: java aJar.jar:junit-4.10.jar org.junit.runner.JUnitCore TestOne
I am getting
Error: Could not find or load main class aJar.jar:junit-4.10.jar
Reasons to Occur Error The error generates because the JVM fails to load the main class or package name. There are some other reasons that generate the same error, as follows: The class has been declared in the wrong package. Dependencies missing from the CLASSPATH.
When the JVM is unable to locate the main class, it's often because it's looking for the corresponding . class files in the wrong classpath. Of course, the way to rectify this problem is to manually specify the classpath by either using packages or specifying the classpath.
You seem to be running under Windows, not LINUX/UNIX. The path separator on Windows is ;
, not :
. Additionally, you haven't put you jar file in the classpath. So what you want is:
java -cp aJar.jar;junit-4.10.jar org.junit.runner.JUnitCore TestOne
This of course assumes that both jars are in the current directory. You should also always avoid putting classes in the default package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With