![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 3
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
use the same command you're using but lose the .class at the end
java HelloWorld |
|
|
|
|
|
#3 |
|
Encoder
|
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. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2005
Posts: 3
Rep Power: 0
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|