Java SE Path Problems
|
If whenever you type
javac MyProg.java
it does not compile your MyProg program; but
instead it spits out some strange
message about a "Bad Command", what's wrong?
Don't panic -- this does not mean that your machine is broken or that you didn't install Java SE 6.0 correctly. The machine says "Bad command" because it doesn't know what the commands javac or java mean! You need to tell DOS that these commands live in the Java SE directory and that whenever it doesn't recognize a command like javac that it should also check the Java SE directory for a possible interpretation of this command.
For XP/2000/ME directions, click here.
For older DOS machines:
At the DOS prompt, type
path
DOS will respond with
PATH=C:WINNT\...;C:\ProgramFiles\.....
where the dots represent all kinds of directory names. This is a list of
all the places DOS looks when it's trying to figure out what a particular
command means. If your Java SE directory is not on this list, your DOS
won't understand the Java SE commands. So you need to
add it to the list.
Type
set path=c:\j2...whateverItIs\bin;%path%
where whateverItIs
is the final digit of your version of Java SE. This
adds your Java SE directory to the rest of the existing path. If you have
put your Java SE directory somewhere else, alter the directory name in
the command above appropriately to match the actual location. Do not
put any spaces in the command above (except between set
and path).
Then try to run the java commands again.
If it still doesn't work, move your *.java files into the Java SE directory -- and you should be able to work there (or in the bin subdirectory of the Java SE directory).
Of course, this means that you'll need to reset your path every time
you turn your machine back on and want to work on the Java programs
again. But there is a way to fix it permanently.
You need to alter (edit) your autoexec.bat file,
which is in your main C: directory.
Please copy this file first to a back up version, e.g.
C: copy autoexec.bat autoexecBACK.bat
because this is the file that has all the important settings for making
your Windows machine run the way you want it.
One of the settings it makes is the PATH.
Open Notepad (or some other editor) to edit the autoexec.bat file and find the line that sets the path. Add your version of the "set path=C:/j2...." command (the one you used earlier) after the line that sets the rest of the path in the autoexec.bat file. Now save the file. Then the next time you open a DOS window (or maybe not until you log in again), the PATH should be set correctly. Of course, if you made an error in editing autoexec.bat, things might not work quite right. In this case, just copy your back up version of autoexecBACK.bat back into autoexec.bat -- and try again.
classpathand DOS will respond with
CLASSPATH=C:stuff.....Type
set classpath=.;%classpath%Leave no spaces except after the word set. This should add the current directory (also known as . ) to your classpath. Then java should know to look in the current directory for the *.class files that your javac compiles are creating.
Directions for XP/2000/ME users:
The procedure is as follows:
If you are using Eclipse, it should now work.
Copyright © 1999-2004: Colorado State University, CS Department. All rights reserved.