I am trying to run a simple java program in linux but getting a NoClassDeffoundError.
Basically, I have the following folder structure:
lib/myRef.jar
src/MyTest.java //there are classes that being referenced in myRef.jar
I compile like this:
javac -cp ../lib/myRef.jar MyTest.java //The class file is being gerenated in the same directory
Then when I try to run:
java -classpath . myRef
I am getting a NoClassDefFoundError on classes that I am referencing in the jar file.
Do I need to reference both lib and the current class that I am running?
Yes, you’ll need to also have myRef.jar on the classpath when running your code using java. Also, you seem to be passing the wrong classname to java, if you want to run your class
MyTestas your main class, then use:Just compiling against the support classes that you use isn’t enough, they’ll also need to be in the classpath when you run your program.