javac not working in windows command prompt
Solution 1
If you added it in the control panel while your command prompt was open, that won't affect your current command prompt. You'll need to exit and re-open or simply do:
set "path=%path%;c:\program files\java\jdk1.6.0_16\bin"
By way of checking, execute:
echo %path%
from your command prompt and let us know what it is.
Otherwise, make sure there is a javac in that directory by trying:
"c:\program files\java\jdk1.6.0_16\bin\javac.exe"
from the command prompt. You can also tell which executable (if any) is being used with the command:
for %i in (javac.exe) do @echo %~$PATH:i
This is a neat trick similar to the which
and/or whence
commands in some UNIX-type operating systems.
Solution 2
Windows OS searches the current directory and the directories listed in the PATH environment variable for executable programs. JDK's programs (such as Java compiler javac.exe and Java runtime java.exe) reside in directory "\bin" (where denotes the JDK installed directory, e.g., C:\Program Files\Java\jdk1.8.0_xx). You need to include the "\bin" directory in the PATH.
To edit the PATH environment variable in Windows XP/Vista/7/8:
Control Panel ⇒ System ⇒ Advanced system settings
Switch to "Advanced" tab ⇒ Environment Variables
In "System Variables", scroll down to select "PATH" ⇒ Edit
(( now read the following 3 times before proceeding, THERE IS NO UNDO ))
In "Variable value" field, INSERT "c:\Program Files\Java\jdk1.8.0_xx\bin" (Replace xx with the upgrade number and VERIFY that this is your JDK's binary directory!!!) IN FRONT of all the existing directories, followed by a semi-colon (;) which separates the JDK's binary directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.
Variable name : PATH
Variable value : c:\Program Files\Java\jdk1.8.0_xx\bin;[existing entries...]
Solution 3
After a long Google, I came to know that javac.exe will be inside JDK(C:\Program Files\Java\jdk(version number)\bin) not inside JRE (C:\Program Files (x86)\Java\jre7\bin) "JRE doesn't come with a compiler. It(JRE) is simply a java runtime environment. What you need is the Java development kit." in order to use compiler javac
javac will not work if you are pointing bin inside jre
In order to use javac in cmd , JDK must be installed in your system...
For javac path
path = C:\Program Files (x86)\Java\jre7\bin this is wrong
path = C:\Program Files\Java\jdk(version number)\bin this is correct
Make sure that "javac.exe" is inside your "C:\Program Files\Java\jdk(version number)\bin"
Don't get confused with JRE and JDK both are totally different
if you don't have JDK pls download from this link
or
http://www.oracle.com/technetwork/java/javase/downloads/index.html
reference thread for JDK VS JRE What is the difference between JDK and JRE?
Solution 4
I know this may not be your specific error, but I once had a leading space in my path and java would work but javac would not.
For what it's worth, I offer the sage advice: "Examine your Path closely".
Solution 5
Try the solutions here: http://techdem.centerkey.com/2009/05/javahome-command-script.html
These are much more robust to change -- like when you upgrade the JDK or JRE, since there is no hard coded path.
The quick solution (if you don't want to read the blog) is
C:\>for /d %i in ("\Program Files\Java\jdk*") do set JAVA_HOME=%i
C:\>set PATH=%PATH%;%JAVA_HOME%
You can then add these lines to a startup/login script.
Comments
-
Dom M. almost 2 years
I'm trying to use
javac
with the windows command prompt, but it's not working.After adding the directory
"C:\Program Files\Java\jdk1.6.0_16\bin\"
to the end of thePATH
environment variable, thejava
command works fine, but usingjavac
gives me the following error:'javac' is not recognized as an internal or external command, operable program or batch file.
-
MultiplyByZer0 over 5 years
-
-
paxdiablo over 14 yearsI don't think that's correct. I can set my path to be nothing but "C:\Program Files\Java\jdk1.6.0_16\bin\" (with trailing slash) and it still works fine.
-
Dom M. over 14 yearsah yes, all i had to do was re-open the command prompt and it worked fine, thanks!
-
Marc Bredt over 13 years+1. The "for %i in (java.exe) do @echo %~$PATH:i" just saved my day. I'm just a occasional Windows user and I just did not know there's could be yet another hidden java.exe in c:\windows\system :)
-
Prashant over 12 yearsI guess unsetting the classpath is better here. I would not use the CLASSPATH variable, especially not on Windows where it is global and affects multiple JREs...
-
user716468 over 11 yearsThe above set path command does not work for me under windows 7. I had to use set path="%path%;c:\program files\java\jdk1.6.0_16\bin. That is without quotes! I am not familiar with windows command line but it seems that quotes are preserved. So having them in the %path% will make it entirely unusable.
-
Morgan Kenyon over 10 yearsFor Step 4. I found that I had to select not jre<yournumber>, but jdk<yournumber>. Then everything else worked fine.
-
itsfarseen over 10 years@user716468, There is a GUI way to do this in windows instead of command line. If you are on windows 7, just type var in start menu search and click on Edit Environment Variables. If you are on Windows XP, right click My Computer, Click on properties, go to advanced tab and click on the Environment variables button on the bottom side. There you can find two list boxes. Find out the one with name PATH from the bottom list box and click on Edit. Now append the path to your JDK preceded by a semicolon. You're Done!
-
x29a over 10 yearsthere is also a "where" command in recent windows command lines
-
M_R_K about 10 yearsNeat and Clear ! Best answer. Worked for me.
-
sedeh over 9 yearsIn my case, for step 4, I opened jdk. In essense, I had this for PATH: C:\Program Files\Java\jdk1.7.0_67\bin. javac.exe was not in the jre but in the jdk.
-
user31389 over 8 yearsFor invoking javac like that I had to use "set PATH=%PATH%;%JAVA_HOME%\bin" (notice the added \bin).
-
RAJESH KUMAR ARUMUGAM almost 7 yearsWorks for Me :)
-
YakovL over 6 yearsI'd suggest to add more annotation to your answer directly instead of just providing a link: the link may get broken. Best regards