问题
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
回答1:
Make sure %JAVA_HOME%/bin is on your %PATH% (or $JAVA_HOME on the $PATH in *nix).
回答2:
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, e.g. C:\java\jdk1.6.0_12\bin\javac ...
3) Add the javac directory to the PATH environment variable
回答3:
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.
回答4:
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).
回答5:
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
回答6:
Common Error Messages from SUN Tutorial page
回答7:
Step 4 (Update the PATH variable) of the JDK installation instructions explains what you should do to make it so that you can just type javac
in the command prompt window.
回答8:
The link below gives a step by step explanation on how to set up java_home and path variables. JAVA_HOME setup
回答9:
Even if I had
- JDK installed
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.
回答10:
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
回答11:
- Check whether you have JDK installed; if not installed, Install
- If JDK is installed, navigate into the bin folder of the installation, and try to execute javac.
- If javac executes, proceed (+:
- If javac does not execute, check your system path, and java path, and return to 2 above!
来源:https://stackoverflow.com/questions/1299750/javac-not-recognized