Java “NoClassDefError” while running the program on Linux

Tags: ,



I have a Java program that imports some of the Weka packages. I basically compiled it using the “javac -classpath CLASSPATH:weka.jar program_name.java” command, and everything was fine.

When I ran it using “java -Xmx2024m -classpath CLASSPATH:weka.jar program_name”, the program threw a “NoClassDefFound” error stating that the main class “program_name” could not be found!

This problem is really puzzling as the compilation worked, and the program_name.class file is present in the folder. The weka.jar is present as well.

Could somebody please tell me what I am doing wrong?

Thanks!

Answer

How about java -Xmx2024m -classpath %CLASSPATH%:.:<path_to>/weka.jar program_name.

The program you are trying to be run ( including its package name ) must be navigable from the directory you are in.

So, if your program was com.dave.MyProgram and you compiled it into /home/dave/bin, and the weka.jar file was in /tmp. then you would try

cd /home/dave/bin

java -Xmx2024m -classpath .:/tmp/weka.jar com.dave.MyProgram

this is creating a classpath containing the current directory and /tmp/weka.jar, and running the fully qualified name of your program.

If your program is not in a package the colland would be

java -Xmx2024m -classpath .:/tmp/weka.jar MyProgram


Source: stackoverflow