aspose file tools*
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
Author

NoClassDefFound error

Kondapally Ashwin
Greenhorn

Joined: May 16, 2006
Posts: 25
Hi,

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.

Thanks,
Ashwin.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

javac HelloWorld.java

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 HelloWorld.java file using the JDK.

http://www.technicalfacilitation.com/examscam/get.php?link=../scja/multimedia/writecompilerunsdk

Good luck!

-Cameron
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Hello,

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

Then from d:\hw directory,

javac Hello.java
set CLASSPATH=.;%CLASSPATH%
java Hello

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

package com.hw;

Then

javac -d . Hello.java
set CLASSPATH=.;%CLASSPATH%
java com.hw.Hello

or

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

Joined: Aug 16, 2005
Posts: 14107
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFound error