• Post Reply Bookmark Topic Watch Topic
  • New Topic

Command Prompt, not working??  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is probably a tough question, but my PC is really
annoying me.

I have netbeans installed, which I use for servlets and JSPs mainly.
But for normal applications, I tend to just use notepad, and then
compile and execute using the command prompt.

I seemed to have done something to my PC, and now for example, when I
try to use command prompt to execute programs, it doesn't work.
The folder I store my programs in is C:\java
In command prompt I would type cd c:\java
Then, javac Hello.java
Then, java Hello
But whats happening now is that when I try to execute with (java Hello),
I keep getting the same message-
Exception in thread "main" java.lang.NoClassDefFoundError: Hello

I've uninstalled the jdk, and then reinstalled it, but still no
change. I've checked the classpath thing, using EDIT C:\AUTOEXEC.BAT,
and this is the same as before, so I don't know whats causing the command
prompt to not run my programs.

Any ideas are much appreciated, I really don't want to have to format
PC just to get this to work.
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Format the PC" Please, spare me!

If you've got the CLASSPATH environment variable set, it needs to include "." (dot), the current directory. Or just say "java -cp . Hello" .
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thats amazing, it worked!!!
Thanks, but still, I don't understand why I can't
just use 'java Hello' like I normally would.

Maybe I accidently removed some necessary files from
the Windows folder, I don't know.

But nevertheless, thanks. You see, I find the Netbeans environment
too small to work in when creating applications, and its offputting.
So at least I can use your recommended command 'java -cp . Hello'
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If CLASSPATH is not set at all, the default is just "." . So perhaps you installed something that set CLASSPATH for the first time, or changed the setting to something that omits the ".:.

Note that on Windows XP, AUTOEXEC.BAT does nothing, although some older install scripts will create one just the same. On Windows ME and older, though, it will indeed set environment variables.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so any ideas how to execute programs from command prompt,
using just 'java Hello'?

I've always used the EDIT C:\AUTOEXEC.BAT command to set the classpath
, then I enter:

PATH C:\JDK\BIN;C:\JDK;%PATH%;
SET CLASSPATH=C:\JDK\JRE\LIB\RT.JAR;.;

Then I save then exit.
But I'm not sure about how this all works, I'm no expert.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a great First Steps introduction to the classpath from Sun, and some next steps from, um, me. See if these help you get comfortable with classpath.
[ October 08, 2005: Message edited by: Stan James ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EXCELLANT!!!

I used the 'set CLASSPATH=' command as suggested in the link,
and its now back to normal.

Cheers, I really didn't want to format, and now I don't need to!!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!