Home > Net >  Getting a NoClassDefoundError for an external junit.jar file
Getting a NoClassDefoundError for an external junit.jar file

Time:08-11

I'm currently trying to compile some test cases for a java RMI uni project that I'm working on.

I have the following file structure.

enter image description here

I am using the following command to compile my files, which compiles without issue:

javac -cp :dependencies/junit-4.3.jar: src/*.java tests/*.java

However, when I go to run java tests.SingleClientTest I am met with the following error: enter image description here

I was wondering if anybody were able to point me in the right direction. Thank you :)

CodePudding user response:

You provided the jUnit jar during compile time, which worked perfectly and compiled your classes properly. When launching the application though, you didn't provide the jUnit jar, therefore the required classes from that library are missing at runtime causing the Exception you see.

To fix the issue, set the -cp (=Classpath) argument as you did when compiling the classes in the first place.

You can try the following:

java -cp :dependencies/junit-4.3.jar: tests.SingleClientTest
  • Related