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 MyTest
as your main class, then use:
java -classpath ../lib/myRef.jar:. MyTest
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.