Java NoClassDefFoundError

One user reported problems trying to run a Java program. We tried to run the program on several computers and some worked but some didn’t. The program was launched by a batch file. The command is something like


java program_name

We got this java.lang.NoClassDefFoundError constantly.

From past experience, it’s usually related to environment variables not set correctly.  I tried to set the JAVA_HOME variable, but it didn’t work. I then found that there is a system variable CLASSPATH being set. The variable caused Java program not to look for classes in the current directory. The workaround is to change the previous command line to

java -classpath . program_name


This post may contain affiliated links. When you click on the link and purchase a product, we receive a small commision to keep us running. Thanks.


Be the first to comment

Leave a Reply