java.lang.NoClassDefFoundError (Linux)

I’m trying to get the java SDK working on Mandrake 10. I get the following errors:

[andrew@localhost java]$ java HelloWorld.class
Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld/class

echo $CLASSPATH returns nothing.

I looked around and it seems there were several ways to set your classpath but each way was a little diffrent and involved editing /etc/profile or $HOME/.bashrc (even /.bash_profile in some cases)

What exactly needs to be done?

Specify the class without the file externsion (.class)

i.e.

java HelloWorld

Kev

wow…uhhh I feel stupid.

Wouldn’t worry too much, you did post it in “Newless Cluebies”…

Kev

Actually, I feel like asking the question:

Why do they make you do it for the .java file and not the .class file, it makes no sense :stuck_out_tongue:

because the jvm would look for a class called “class” in the ‘helloworld’ package.
when you’re compiling, you are accessing a file.
When you are launching a class (calling its main() method, in fact), the class can eventually be in an other form than a .class file stored on a medium. The file extension is only revelant in the filesystem context, thus has not to be set when giving reference of a class to find.