'javac' is not recognized as an internal or external command

'javac' is not recognized as an internal or external command, operable program or batch file error comes when you try to compile a Java source file using javac command e.g. javac Helloworld.java but your PATH is not set properly. It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable. Here is how this error looks like in command prompt of windows machine :

'javac' is not recognized as an internal or external command error windows



Steps to fix 'javac' is not recognized as an internal or external command :

Let's see how to fix this problem to compile and run Java program from command line :

1) Open command prompt in Windows by clicking Start button and then typing cmd on run window, as shown in following screenshot :

How to open command prompt in windows


2) Type echo %PATH%,  it will now show you all the directories which are available in PATH environment variable. Now copy this PATH output into your text editor e.g. Notepad or Word-pad and search if it contains the JDK installation directory or JAVA_HOME. For example, if your JDK is installed on "c:\program files\java\jdk1.8.0", then PATH should include "c:\program files\java\jdk1.8.0\bin". It's important to include bin directory because all executable required to compile, run and debug Java program are stored in bin directory.  Sometime you will also see like %JAVA_HOME%\bin , where JAVA_HOME is another user defined environment which points to Java installation directory. 



3) If PATH doesn't contain bin directory of JDK, then you can add them into PATH by following command

set PATH = %PATH%;"c:\program files\java\jdk1.8.0\bin

This is also known as setting PATH in Java. Once PATH is set you can compile, run and monitor Java programs by using various tools which comes with JDK installation. If you are not very familiar with setting environment variable from command prompt, you can also use settings window as shown in this article.

4) Don't forget to close the current command prompt and open a new one before running the javac command again.  Any change in environment variable is only available to new cmd windows.


That's all about how to fix 'javac' is not recognized as an internal or external command, operable program or batch file error in Windows. You might get similar error e.g. 'java' is not recognized as an internal or external command, operable program or batch file, if you try to run an already compiled Java program and PATH is not set in your machine.


No comments:

Post a Comment