Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javac not working in windows command prompt

People also ask

Why is javac not working in CMD?

javac is not recognized is an error occurs while we compile the Java application. It is because the JVM is unable to find the javac.exe file. The javac.exe file is located in the bin folder of the JDK. The reason behind to occur the error is that the PATH is not added to the System's environment variable.

What is javac in command prompt?

Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.


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.


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:

  1. Control Panel ⇒ System ⇒ Advanced system settings

  2. Switch to "Advanced" tab ⇒ Environment Variables

  3. 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...]

Screenshot


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

https://jdk.java.net/

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?


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".