Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 832
Haritha Avatar asked Jun 13 '11 17:06

Haritha


People also ask

How do I resolve NoClassDefFoundError in Junit?

To resolve module dependency, we use the module path. However, adding external jars in the module path does not make them available for the class loader. Hence the class loader considers them as missing dependencies and throws the NoClassDefFoundError.

What is main thread exception?

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.


1 Answers

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

like image 199
Abhi Avatar answered Oct 05 '22 23:10

Abhi