Colorado State University

Java SE Path Problems
On Windows Machines (DOS)

Possible Path Problems when running Java SE 6.0 on Windows Machines

So you've installed Java SE 6.0 on your machine, but it doesn't work!

There are a couple of possible reasons
related to the path settings on your Windows machine

  1. CLASSPATH setting
  2. PATH setting

PATH Problems

If whenever you type

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

DOS will respond with
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.


        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.


If the compiler or Java interpreter complain that they can't find a class you know is in your current working directory, you might need to fix your CLASSPATH. At the DOS prompt, type
and DOS will respond with
        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:

  1. Click on the Start menu button.
  2. Right click on "My Computer."
  3. Click on Properties.
  4. Click on the Advanced tab.
  5. Click on the "Environment Variables" button near the bottom.
  6. A dialog box comes up with two boxes: In the bottom box, look for "Path" and highlight that line. Then click on "Edit"
  7. A small dialog box appears. In the second text field for the value, at the END of the line, add a semicolon then the path to where your java.exe file is. To determine this, you can use the Search program in Windows and search for "java.exe". It should then show you the full path of where it is. A hint, is that the path should end with "bin". so, at the end of the text field, add something like: ;C:\j2sdk1.4.2_03\bin
  8. Click "OK."
  9. Now, in the top box, click on the "New" button.
  10. In the first field, enter "classpath" as one word. For the value in the second field, enter a single period.
  11. Click "OK."
  12. Click "OK."
  13. Click "OK."

If you are using Eclipse, it should now work.

Back to CS Help Page
Back to CSU Home Page

Copyright © 1999-2004: Colorado State University, CS Department. All rights reserved.