jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NoClassDefFoundError" Watch "Exception in thread "main" java.lang.NoClassDefFoundError" New topic

Exception in thread "main" java.lang.NoClassDefFoundError

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 632

hello everybody, I have problem in setting path.

I had installed java in c: drive.
I had set a path lilke this C:\Program Files\Java\jdk1.6.0_05\bin;.;
The program compiles fine but at run time it throw exception as NoClassDeffFoundError.

Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Thanks in advance

Life is easy because we write the source code.....
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Did you run the java command from the path of the class file ? is it inside package.
I suggest to compile and run a program from sun's site as described in it and then work on your class.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 632

Thanks for your reply,
actually if I set path as

java -classpath . Test

then the programme run succcessfully, but if I set only path as
java Test
it throws Exception.

why is it so?
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

First things first.. PATH and CLASSPATH are different and you got to mention it as CLASSPATH , when you mean CLASSPATH.Secondly when you use -classpath option , it means you are overiding your CLASSPATH value sent in your environment.

So , in the first case it worked because your class lies in the present working directory (pwd) and your -classpath option says "." , which means look for classes only pwd.

In next case , you have not specified so it uses the CLASSPATH value defined in the environment. But your CLASSPATH should either have complete path where Test.class lies or the "." in order for it to find the class. So make sure you add "." to your CLASSPATH variable as well.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
If you set up the system classpath yourself, it is easier to delete the system classpath.
I agree. Here's the link: http://aspose.com/file-tools
subject: Exception in thread "main" java.lang.NoClassDefFoundError
It's not a secret anymore!