views:

72

answers:

2

I tried the following in cl:

javac Main.java

The shell gives an error that "javac" is not a recognized command. I know for a fact I have the Java Platform installed. What could be wrong?

(I use "cd" to set the directory first)

A: 

Add /bin folder to your environment variables.

How do I set or change the PATH system variable?

zengr
I followed the instructions for Vista (setting the PATH system variable to the directory of the src) I tried it again and it gave the same error
Alan
You need to restart windows after you edit the environment variable.
zengr
@Alan Not the location of the src, the location of javac. On windows probably something like C:\Program Files\Java\jdk1.6.0_18\bin
Tom
@zengr no you don't, just re-launch the command window.
Tom
In windows, you need to restart. In linux you dont.
zengr
@zengr: this is not true. You just need to close all opened command prompt windows and reopen a new one. @Alan, it's `javac.exe`. If you don't have such file, you probably haven't installed [JDK](http://java.sun.com/javase/downloads/widget/jdk6.jsp) (for developers), but just [JRE](http://java.com) (for endusers).
BalusC
Its not working still so Im going to restart
Alan
@BalusC I was in the wrong directory I've found It now.
Alan
Still not working :(
Alan
though "C:\Program Files\Java\jdk1.6.0_18\bin\javac.exe" Main.java works
Alan
@zengr, the value of PATH is read by the CMD.EXE window when opened. Hence all _new_ CMD.EXE windows will have the new PATH value.
Thorbjørn Ravn Andersen
@Alan Can you post the value you typed in "PATH" in the Environment Variables.
zengr
+2  A: 

javac is most likely not on the PATH, and you must give the full path in your command.

Thorbjørn Ravn Andersen
What do you mean? Typing in this? <code>javac C:/Users/......./Main.java</code> That did not work
Alan
No, `c:/path/to/jdk/bin/javac.exe Main.java`. But better is to add `c:/path/to/jdk/bin` to `%PATH%` environment variable so that you don't need to enter the full `javac` path everytime.
BalusC
If you've got Java environment variables set up, you can also do something along the lines of `%JAVA_HOME%\bin\javac.exe Main.java`.
Brian S
@brian, he clearly haven't.
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen: just giving more options :)
Brian S