exception in thread 'main' java.lang.NoClassDefFoundError:

Haritha picture Haritha · Jun 13, 2011 · Viewed 301.1k times · Source

The following program is throwing error:

public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello World!"); 
    }
}

CLASSPATH C:\Program Files\Java\jdk1.6.0_18\bin\

Path C:\Program Files\Java\jdk1.6.0_18\bin\

JAVAHOME C:\Program Files\Java\jdk1.6.0_18\bin

Can you please tell me the root cause?

Answer

Abhi picture Abhi · Nov 2, 2013

I found one another common reason. If you create the java file inside a package using IDE like eclipse, you will find the package name on the top of your java file like "package pkgName". If you try to run this file from command prompt, you will get the NoClassDefFoundError error. Remove the package name from the java file and use the commands in the command prompt. Wasted 3 hours for this. -- Abhi