What can I do when I keep receiving the error
'javac' is not recognized as an internal or external command, operable program or batch file
when I want to compile my jar or .class
file?
Thanks
确保%JAVA_HOME%/ bin位于%PATH%(或* nix中的$ PATH上的$ JAVA_HOME)。
It means that it is not in your path. You have the following options:
1) Change to the directory where javac lives before calling it.
2) Use the full path to javac when making the call, eg C:\\java\\jdk1.6.0_12\\bin\\javac ...
3) Add the javac directory to the PATH environment variable
This just means that javac isn't in your PATH variable.
On Windows, you just have to add the folder that contains javac.exe to the PATH environment variable (Win+Pause/Break).
On Linux/Mac/Unix, just append that directory to $PATH in .bashrc or similar.
The error that you are seeing is generated by Windows, and isn't specific to Java. That error means that you typed a command and Windows could not find the command by that name.
The easiest way of rectifying the situation is to ensure that Java is properly installed in your system's PATH
.
First, ensure that you have a JDK installed (and not just a JRE). Your next best bet is to add an environment variable called JAVA_HOME
and point it at the base install directory for the version of Java that you installed.
Next, modify your PATH
environment variable by prepending the string %JAVA_HOME%\\bin;
to whatever is already in your PATH
. If you look at the contents of that directory, you will see that javac
is in there (along with a number of other Java development tools).
You have to install JDK (which includes javac compiler) and ensure that it's in the path. See http://java.sun.com/javase/downloads/index.jsp
Even if I had
JAVA_HOME
defined %JAVA_HOME%\\bin
present in my %PATH%
I still had this error. I resolved it by eliminating the JRE from my path variable. It was put before JAVA_HOME
, has no javac
. It seems Windows can't find javac
in JAVA_HOME\\bin
in this case.
JDK安装说明的步骤4(更新PATH变量)说明了应该做什么,以便您只需在命令提示符窗口中键入javac
即可。
For Windows
Control Panel > System ...Then click Advanced System Setting (left pane)...then popup window will open...then click Environment Variables ...Then another window will open...click New and add enter information below
Variable name : PATH
Variable value : C:\\Program Files\\Java\\jdk1.7.0_45\\bin [* make sure this is the right path for you ]
Then it should work
The link below gives a step by step explanation on how to set up java_home and path variables. JAVA_HOME setup
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.