java.lang.NoClassDefFoundError

Well I found the dreaded java.lang.NoClassDefFoundError problem on my computer few days ago.

The test.java just prints hello world to screen, it compiles and runs fine with JCreator (IDE which I use to learn java)... when I tried to use command prompt to execute it just comes up with the error...

I've read about reseting classpath and all but I didn't work, I just copied the classpath from JCreator settings and it doesn't seem to work either...

Any ideas on how to solve this?

Thanks

C:\Temp>javac test.java

C:\Temp>java test

Exception in thread"main" java.lang.NoClassDefFoundError: test

C:\Temp>set

Classpath=C:\Program Files\Java\jdk1.5.0_11\jre\lib\rt.jar;C:\Program Files\

\jdk1.5.0_11\lib\dt.jar;C:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;C:\P

am Files\Java\jdk1.5.0_11\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.5

1\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.5.0_11\jre\lib\ext\s

e_provider.jar;C:\Program Files\Java\jdk1.5.0_11\jre\lib\ext\sunpkcs11.jar

Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program File

mmon Files\Adobe\AGL;C:\Program Files\Diskeeper Corporation\Diskeeper\;C:\WI

S\system32\WindowsPowerShell\v1.0;C:\Program Files\Java\jdk1.5.0_11\bin

[1346 byte] By [rugaea] at [2007-11-27 11:23:43]
# 1

Instead of cpoying all that stuff, you should have pondered for a minute what the classpath actually is. So you wold have seen that you need to include the location of *your classes*.

Try

java -cp . mypackage.Myclass

or even an executable JAR, and leave the variable alone.

CeciNEstPasUnProgrammeura at 2007-7-29 15:53:16 > top of Java-index,Java Essentials,New To Java...
# 2

Executable jar worked even if the command "java test" didn't.

-cp worked cheers.

So is it possible to make it search for its class file automatically? I must have a misconfiguration somewhere...

rugaea at 2007-7-29 15:53:16 > top of Java-index,Java Essentials,New To Java...
# 3

You can add a "." to your classpath and the jvm will always look in the current directory for your classes

kevin.mcguinnessa at 2007-7-29 15:53:16 > top of Java-index,Java Essentials,New To Java...
# 4

Adding the classpath=.;...etc didn't make a difference for me.

> or even an executable JAR, and leave the variable alone.

Good advice... I cleared my classpath all together in command prompt:

c:\>set classpath=

And everything worked again. eg "> java test" works now.

rugaea at 2007-7-29 15:53:16 > top of Java-index,Java Essentials,New To Java...