Saturday, December 15, 2012

Java Error : 'javac' is not recognized as an internal or external command

So you are trying to compile your Java source file and getting "'javac' is not recognized as an internal or external command". If this is your first Java program or HelloWorld than I suggest to go through How to compile and run HelloWorld in Java because that explains what do you need before you compile and run any Java program. If you have crossed that level and knows about How to set PATH in Java then there is something wrong while setting PATH in Java. Anyway let's see when does you get this error and from where does 'javac' is not recognized as an internal or external command comes. This is an standard error in Windows command line when you type a command which is not available in System PATH, here javac command which is used to compile Java source file and produces class files are not in PATH. Best way to verify this is executing following command :

# echo %PATH%

If you see your JDK installation folder or JAVA_HOME in PATH and included bin directory which contains all java binaries including javac and java commands which is used to compile and run Java program. Most likely your PATH may not have JDK/bin in PATH, if that's the case just include bin folder of JDK in your PATH. See how to set PATH for Java in Windows for step by step guide.

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

Cause of 'javac' is not recognized as an internal or external command  fix solution
Other cause of  " javac is not recognized as an internal or external command " could be that you only have JRE in your System and not JDK, which means you can only run already compiled Java program and can not compile Java program because JRE doesn't contain javac in there bin folder. To know more about JRE and JDK, see difference between JRE and JDK. In this case you need to download and install Java in your System. You can download current version of Java from Oracle's site.

Another possible reason of  " javac is not recognized as an internal or external command "  is setting PATH with incorrect directory e.g. path may not contain forward slash or missed something. Best way to verify this is just copy path of JDK from PATH variable and execute in command line, if you can not get into that directory which means path to JDK installation folder is incorrect. In this case go to bin directory of JDK installation directory and copy its address from address bar and add into PATH to make this work.

So root cause of  "javac is not recognized as an internal or external command " is that system is not able to find javac command from its PATH. just double check PATH and add bin folder of JDK installation directory in path, if not included already. Remember to close and re open command prompt once you make this change, this will fix  " javac is not recognized as an internal or external command " error.

Other Java tutorials for Beginners

No comments :

Post a Comment