[java] javac not working in windows command prompt

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 the PATH environment variable, the java command works fine, but using javac gives me the following error:

'javac' is not recognized as an internal or external command, operable program or batch file.

This question is related to java windows command-prompt javac

The answer is


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.


Change the folder "jdk1.7.0_45" "jdk1_7_0_60" and update the path in Windows environment. Otherwise, the path ignores the dot at the front which stands for hidden file and so the folder is not displayed in PATH strings.


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


Give it as "C:\Program Files\Java\jdk1.6.0_16\bin". Remove the backslash it will work


";C:\Program Files\Java\jdk1.6.0\bin" sometime you may forget to put semicolon on last existing path.


When i tried to make the .java to .class the command Javac didnt work. I got it working by going to C:\Program Files (x86)\Java\jdk1.7.0_04\bin and when i was on that directory I typed Javac.exe C\Test\test.java and it made the class with that tactic. Try that out.


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?


Ensure you don't allow spaces (white space) in between paths in the Path variable. My problem was I had white space in and I believe Windows treated it as a NULL and didn't read my path in for Java.


I faced the exact same problem that java would work but javac would not on a cmd prompt in Windows 8.

The problem occured because I forgot to remove '>' at the end of the path name, i.e., it was like this:

C:\Program Files\Java\jdk*\bin>

where it was suppose to be like this:

C:\Program Files\Java\jdk*\bin

I appreciate this is an old question now but my solution wasn't an answer on here so posting it in case anyone else tries all the rest.

In my case, a previous install of the Java JRE (in ProgramData/Oracle/Java) had a path variable at the top of my list of path variables. The contents of that "Oracle" path had a java.exe but not a javac.exe. I added my full JDK path to the top of the list of path variables, ahead of the "Oracle" one, and it then picked up javac.exe as well as java.


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


I just had to do this to get this to work on windows 7 64.

Open up a command prompt (cmd.exe) and type:

set CLASSPATH=C:\Program Files\Java\jdk1.7.0_01\bin

Make sure you reopen all running command prompt Windows to get the environment variable updated as well.


I was having the same problem posted in this title. Java would work, but javac would not in the Windows command prompt (cmd.exe).

For me, it was simply that I had placed a space when adding C:\Program Files\Java\jdk1.8.0\bin to the end of my %PATH% environment variable.
Remove the space between the ; and the next file path.


for /d %i in ("\Program Files\Java\jdk*") do set JAVA_HOME=%i
set JAVA_HOME

this solution worked to me


The path will only be set for the administrator account. Therefore it is important to launch command prompt as administrator, if you are not already.


Okay this can not be the case always but many of us have done this mistake in the past and few out of those are still not aware of it, which is, every time you append a path (any path) of any environment variable, you're likely to hit the space bar right after the "semicolon" (as you normally would, after the "period" while typing in an editor).

This will create a leading space in the path e.g " C:\Program Files\Java\jdk1.6.0\bin" and therefore "javac.exe" won't be found by the system.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to command-prompt

CMD command to check connected USB devices How do I kill the process currently using a port on localhost in Windows? PowerShell The term is not recognized as cmdlet function script file or operable program open program minimized via command prompt How to connect to SQL Server from command prompt with Windows authentication How to see the proxy settings on windows? How do I type a TAB character in PowerShell? Batch file to split .csv file Aliases in Windows command prompt Change all files and folders permissions of a directory to 644/755

Examples related to javac

Setting up enviromental variables in Windows 10 to use java and javac "Javac" doesn't work correctly on Windows 10 Error:java: invalid source release: 8 in Intellij. What does it mean? Javac is not found Maven Unable to locate the Javac Compiler in: Unable to locate an executable at "/usr/bin/java/bin/java" (-1) javac is not recognized as an internal or external command, operable program or batch file javac option to compile all java files under a given directory recursively Creating a batch file, for simple javac and java command execution javac : command not found