can not compile my java program

Discussion in 'OT Technology' started by toker, Apr 4, 2004.

  1. toker

    toker Guest

    i downloaded the j2sdk 1.4.2 and installed it but when i go to the command prompt and type javac it says that it is not recognized as a command. is htere something else that I need to compile?
  2. toker

    toker Guest

    well i found the javac.exe. what do i have to do so that it will run from the prompt when i enter "javac"?
  3. Leb_CRX

    Leb_CRX OT's resident terrorist

    Apr 22, 2001
    Likes Received:
    Ottawa, Canada
    you haev to set the path in autoexec.bat


    or someshit like that, basically you gotta point it to the directory the file's in
  4. Ractoon

    Ractoon Shibumi in progress...

    Apr 30, 2001
    Likes Received:
    Note: Windows XP/2000/ME info toward the bottom on this, have fun

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

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

    CLASSPATH setting
    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 J2SE 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 J2SE directory and that whenever it doesn't recognize a command like javac that it should also check the Java J2SE 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 J2SE directory is not on this list, your DOS won't understand the Java J2SE commands. So you need to add it to the list.

    set path=c:\jdk1.3.whateverItIs\bin;%path%

    where whateverItIs is the final digit of your version of Java J2SE. This adds your Java J2SE directory to the rest of the existing path. If you have put your Java J2SE 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 J2SE directory -- and you should be able to work there (or in the bin subdirectory of the Java J2SE 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 PC 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:/jdk.2...." 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.


    CLASSPATH Problems
    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:

    Click on the Start menu button.
    Right click on "My Computer."
    Click on Properties.
    Click on the Advanced tab.
    Click on the "Environment Variables" button near the bottom.
    A dialog box comes up with two boxes: In the bottom box, look for "Path" and highlight that line. Then click on "Edit"
    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
    Click "OK."
    Now, in the top box, click on the "New" button.
    In the first field, enter "classpath" as one word. For the value in the second field, enter a single period.
    Click "OK."
    Click "OK."
    Click "OK."
  5. toker

    toker Guest

    thank you leb_CRX and Ratcoon I know remember my teacher talking about this but he didnt really explain it thanks a lot for the help!

Share This Page