Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 22nd, 2005, 8:18 PM   #1
churi55
Newbie
 
Join Date: Sep 2005
Posts: 3
Rep Power: 0 churi55 is on a distinguished road
Setting the PATH variable

I am new to JAVA and I'm trying to get started with my environment.

Following the instructions in the book, I have successfully compiled a "Hello World" program but am unable to run the program from MS-DOS.

If I type the command "set CLASSPATH=" in the command prompt and then run the program, I do get the expected "Hello World!" but without it, I just get the message "Exception in thread "main" java.lang.NoClassDefFoundError:"

I did set the User Variable PATH to include the bin directory and I also included the bin directory to "CLASSPATH" and "Path" in the Systems Variables.

Can anybody tell me what else I could do (besides typing "set CLASSPATH=") to run my HelloWorld.class file?
churi55 is offline   Reply With Quote
Old Sep 22nd, 2005, 9:30 PM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
use the same command you're using but lose the .class at the end
java HelloWorld
OpenLoop is offline   Reply With Quote
Old Sep 23rd, 2005, 8:40 AM   #3
susam_pal
Encoder
 
Join Date: Sep 2005
Location: India
Posts: 12
Rep Power: 0 susam_pal is on a distinguished road
Send a message via Yahoo to susam_pal
as a beginner you should keep your CLASSPATH environment variable empty.

setting the CLASSPATH variables makes sense only when you are treating some folders as the base for packages. you will learn packages later as you proceed.

when you set the CLASSPATH to include your jdk/bin directory, your programs do not run. the reason is, when you do that, the CLASSPATH variable doesn't include the current directory. the current directory is represented as .(dot).

So my advice would be to leave the CLASSPATH variable empty by the command:-

SET CLASSPATH=

when you leave it empty, java automatically searches the current directory for the class files!

if at all you don't want to follow my advice and want to set the CLASSPATH variable for experimenting, then do not forget to include the current directory in the variable.

let us say you want to add the folder "C:\JDK\BIN" to the CLASSPATH variable, then you must set it as

SET CLASSPATH=C:\JDK\BIN;.

the dot in the end ensures that java would search the current directory too for locating the .class files.
susam_pal is offline   Reply With Quote
Old Sep 26th, 2005, 5:21 PM   #4
churi55
Newbie
 
Join Date: Sep 2005
Posts: 3
Rep Power: 0 churi55 is on a distinguished road
Thanks you for the advice.

After adding a ";." at the end of the CLASSPATH variable, I am now able to successfully run .class files from the command prompt window.
churi55 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC