"NathanK" <firstname.lastname@example.org> wrote in message
> Hi Guys,
> im starting out in java and i'm getting the error: Exception in thread
> "main" java.lang.NoClassDefFoundError: blurf
> if i run "javac blurf.java", it compiles fine and without any troubles.
> when i try to run it (its a simple hello world program) i get the above
> i need some help :)
Read Question 5 and 8.
How do I set the CLASSPATH variable for the Java Development Kit ?
Generally, you do not set the CLASSPATH environment variable for a standard
SDK or JRE installation. The CLASSPATH environment variable is set for other
reasons, usually the installation of third-party libraries. Some people
(including myself) argue that setting the CLASSPATH environment variable at
all is bad practice; it should be set dynamically at each build. This keeps
the build machine clean from potential "contamination" from libraries in the
CLASSPATH. Setting the CLASSPATH environment variable was required for
installation of the SDK in versions prior to 1.2. This "myth" has
unfortunately carried over to later versions of Java and confusion has
resulted. A good rule of thumb is, "If you don't know how to set the
CLASSPATH (since you are relatively new to Java), don't set the CLASSPATH at
all". More information on the CLASSPATH environment variable can be found at
What does this mean "Exception in Thread "main"
java.lang.NoClassDefFoundError <something> " ?
This means that the Java Virtual Machine (JVM) cannot find the class that
you are referring to. The error is followed by the class name that the JVM
was asked to load. The directory that contains this class must be in your
CLASSPATH environment variable. If your CLASSPATH is not set to anything,
then the class must be located in the same directory from which the JVM is
invoked (package relative). The JVM is generally (but not always) invoked by
executing the java executable followed by the class name at a command line.
One common problem arises when executing a jar file (using the -jar switch),
which ignores all CLASSPATH settings, except for that specified in the Java
ARchive manifest file. This may be contrary to general intuition, but it
makes perfect sense when you think about it. This is outlined in The JAR
A common error is to append the .class file extension to the class name when
invoking the JVM; this will result in an error similar to the following:
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass/class
Fix this problem by removing the .class file extension from your command.
> java MyClass.class
> java MyClass
(BInfTech, Cert 3 I.T.)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform