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

NoClassDefFoundError

george zhao
Greenhorn

Joined: Jul 02, 2006
Posts: 7
I wrote a few codes.

public class Hello{

public static void main( String args[] ){

System.out.println( "My test" );

}

}

then " javac Hello.java "

then " java Hello",
System throws out "Exception in thread "main" java.lang.NoClassDefFoundError: Hello"

In WindowsXp's cmd,I use "echo %classpath%" ,it returns:
"D:\Program Files\Java\jdk1.5.0_11\bin;D:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;D:\Program Files\Java\jdk1.5.0_11\jre\lib\rt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.5common\lib"

I suspected I set wrong classpath. Pls help me.
[ July 18, 2007: Message edited by: george zhao ]

How can I enlarge my brain memory?
Mike Guze
Greenhorn

Joined: Jun 09, 2007
Posts: 11
Hi,
use "java -cp . Hello"

with -cp option you are telling to JVM where to find your classes
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by george zhao:
...In WindowsXp's cmd,I use "echo %classpath%" ,it returns:
"D:\Program Files\Java\jdk1.5.0_11\bin;D:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;D:\Program Files\Java\jdk1.5.0_11\jre\lib\rt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.5common\lib"...

If you're going to have a system classpath, it should probably include a dot (.) for the current directory.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
george zhao
Greenhorn

Joined: Jul 02, 2006
Posts: 7
That does really help me lot.
Thanks a million , both of you.
"." means current folder, does it?

And
if JDK's version is below 1.5, pls "java -classpath . Hello"
[ July 18, 2007: Message edited by: george zhao ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by george zhao:
... "." means current folder, does it? ...

Yes. Without that, the JVM would look for the class in each of the paths listed in the classpath, and when it can't find it, it would throw a NoClassDefFoundError. See How classes are found in the Java documentation.

Both -cp and -classpath were java options in 1.4. The documentation omits -cp as a javac option (specifying only -classpath), but as I recall, -cp did work.
[ July 19, 2007: Message edited by: marc weber ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFoundError