java.lang.NoClassDefFoundError

Hi all,

I having problems running a java class.

I am using eclipse. I create a program in eclipse (hello world). It compiles and runs using eclpise ok.

The problem is when I compile it using terminal (javac command) it compiles ok, but when I try to run it (java comand) I get the following error.

java.lang.NoClassDefFoundError

I know it is a classpath issue, but I don't know what causes it or how to correct it.

Regards Wayne.

iMac 24", Mac OS X (10.5.7)

Posted on Jun 5, 2009 6:58 PM

Reply
2 replies

Jun 6, 2009 6:26 PM in response to WayneAnthony

Hi WayneAnthony,

Assume I have the code in Hello.java:

/*
Hello.java, simple hello world example
*/
public class Hello
{
public static void main (String[] args)
{
System.out.println("Hello, World!");
}
}


After compiling Hello.java with javac, you can run it from the command-line using
java Hello # not Hello.java or Hello.class!


So compiling and running looks like:
javac Hello.java
java Hello

Hello, World!

In this case, everything works fine. If I try to specify the full name for the 'java' command, I get the problem you mentioned:
java Hello.java

Exception in thread "main" java.lang.NoClassDefFoundError: Hello/java
java Hello.class

Exception in thread "main" java.lang.NoClassDefFoundError: Hello/class

I don't think the CLASSPATH is really causing problems in this case.

I hope that helps!
Caleb

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

java.lang.NoClassDefFoundError

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.