File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes NoClassDefFound error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFound error" Watch "NoClassDefFound error" New topic

NoClassDefFound error

Kondapally Ashwin

Joined: May 16, 2006
Posts: 25

I am getting a runtime exception when I try to run any java program after compiling it. The message I am getting is

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld.

I have set the path to set path = C:\j2sdk1.4.2_07\bin; and classpath to set classpath = .;C:\j2sdk1.4.2_07\lib;. I have even tried to place the program in the bin folder of j2sdk1.4.2_07 but am still getting the same exception.

Please advise.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

So, you're having trouble running it. Did you have success compiling it? It must be compiled before it is run.


Then you can run it with the java command

java HelloWorld

Here's a multimedia tutorial for you that shows you exactly how to write, compile and run a file using the JDK.

Good luck!

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

If you've set CLASSPATH, and set it wrong, then Kameron's instructions won't work; I suspect that's already what you're trying. What you need to do is quickly tell java to ignore whatever you've set as the CLASSPATH, and the easiest way to do that is to specify a value on the command line. So try

java -cp . HelloWorld

That's java space dash cp space dot space HelloWorld.

[Jess in Action][AskingGoodQuestions]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257


Assume you are in d:\hw directory, and source file name is

Then from d:\hw directory,

java Hello

& One More thing , if your source file is having package then, assume
the package is

package com.hw;


javac -d .
java com.hw.Hello


java -cp . com.hw.Hello
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15080

Originally posted by Kondapally Ashwin:
H... and classpath to set classpath = .;C:\j2sdk1.4.2_07\lib;.

You do not need to include the lib directory of the JDK into the classpath.

Just make sure that the CLASSPATH variable is not set at all. If it is not set, Java by default looks for classes in the current directory.

More info: How Classes are Found

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: NoClassDefFound error
It's not a secret anymore!