1

I am attempting to use JUnit for the first time, but I seem to be having some issues when running my compiled test runner. I am using java from the command-line and running macOS.

I successfully compiled my two jar files and 4 java source files using the following command:

javac -classpath junit-4.12.jar:jar2.jar StackLinkedTestRunner.java 2.java 3.java 4.java

However, when I execute java StackLinkedTestRunner, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore at StackLinkedTestRunner.main(StackLinkedTestRunner.java:9) Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more

I've googled the error, but I really don't understand any of the returned problems or solutions. I would greatly appreciate it if people could please take the time to explain what I'm doing incorrectly and how I can go about fixing it.

handler's handle
  • 375
  • 1
  • 2
  • 10
  • This is super-basic stuff. Don't confuse yourself with JUnit ... when you don't understand how you make javac and java work nicely together regarding that classpath aspect. In essence: when your .java source has dependencies on other JARs to allow compiling, then you need those JARs in your classpath also when running your class using Java. As said: super basic stuff; documented a zillion times out there. – GhostCat Apr 04 '17 at 08:29

1 Answers1

0

You are setting the classpath for the java compiler but you have to set the classpath for the java execution as well.

Daniel Bickler
  • 1,119
  • 13
  • 29