# [java] Windows - Java - Problems

This topic is 4928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am having a slight problem in Windows with running java programs from the command prompt. Basically, I can compile the programs but when i run a java program (ie. c:\java Test) it throws a
Exception in thread "main" java.lang.NoClassDefFoundError: Test

anyway, long story short. I run this within eclipse or even netbeans, the program runs. I reboot to linux, run it there from a terminal window, runs fine. I figured this had something to do with my path settings..so i checked those, those looked ok. So I can't figure out why it allows me to compile the program, but not run it from the command line. Any thoughts? ippo.

##### Share on other sites
is your program called 'java test', including a space in the name ? if so, make a program with a proper name (without spaces) and it should run fine.
you can always try calling it using quotes, ie "c:\java test", which is probably what Eclipse does anyway.

##### Share on other sites
i guess i shouldn't really say program, that might be throwing you off. I mean the class name is "Test" (this is arbitrary anyway) and i do my old skool:

c:\javac Test.java (to compile)
c:\java Test (to execute)
Exception in thread "main" java.lang.NoClassDefFoundError: Test

is what happens. and like i've said, I can run this in several IDE's and also from the terminal command prompt within linux. I don't know why it refuses to do so in windows since it compiles fine.

##### Share on other sites
Have you tried adding the classpath to the command line?

java -classpath . test

##### Share on other sites
You can actually set CLASSPATH as an environment variable so you don't have to say it on the command line every time. To do this, go to Control Panel > System > Advanced > Environment Variables, and press New, type CLASSPATH for name, and . for value.

##### Share on other sites
^worked

although I'm still baffled by why I'll always have to do that for every thing i run from the command line now... Before i formatted/reinstalled it never hassled me one bit, unless i was creating packages and such. oh well.

##### Share on other sites
Older versions of Java automatically set the classpath to include the current directory. I think at v1.3, it changed so you have to have it set even for the current directory.

##### Share on other sites
that's probably the reason... such a dumb thing to do ;d