javac not recognized

早过忘川 提交于 2019-11-30 19:32:22

Make sure %JAVA_HOME%/bin is on your %PATH% (or $JAVA_HOME on the $PATH in *nix).

It means that it is not in your path. You have the following options:

1) Change to the directory where javac lives before calling it.

2) Use the full path to javac when making the call, e.g. C:\java\jdk1.6.0_12\bin\javac ...

3) Add the javac directory to the PATH environment variable

This just means that javac isn't in your PATH variable.

On Windows, you just have to add the folder that contains javac.exe to the PATH environment variable (Win+Pause/Break).

On Linux/Mac/Unix, just append that directory to $PATH in .bashrc or similar.

Adam Batkin

The error that you are seeing is generated by Windows, and isn't specific to Java. That error means that you typed a command and Windows could not find the command by that name.

The easiest way of rectifying the situation is to ensure that Java is properly installed in your system's PATH.

First, ensure that you have a JDK installed (and not just a JRE). Your next best bet is to add an environment variable called JAVA_HOME and point it at the base install directory for the version of Java that you installed.

Next, modify your PATH environment variable by prepending the string %JAVA_HOME%\bin; to whatever is already in your PATH. If you look at the contents of that directory, you will see that javac is in there (along with a number of other Java development tools).

You have to install JDK (which includes javac compiler) and ensure that it's in the path. See http://java.sun.com/javase/downloads/index.jsp

Step 4 (Update the PATH variable) of the JDK installation instructions explains what you should do to make it so that you can just type javac in the command prompt window.

The link below gives a step by step explanation on how to set up java_home and path variables. JAVA_HOME setup

Jozsef

Even if I had

  • JDK installed
  • JAVA_HOME defined
  • %JAVA_HOME%\bin present in my %PATH%

I still had this error. I resolved it by eliminating the JRE from my path variable. It was put before JAVA_HOME, has no javac. It seems Windows can't find javac in JAVA_HOME\bin in this case.

For Windows

Control Panel > System...Then click Advanced System Setting (left pane)...then popup window will open...then click Environment Variables...Then another window will open...click New and add enter information below

Variable name: PATH

Variable value: C:\Program Files\Java\jdk1.7.0_45\bin [*make sure this is the right path for you]

Then it should work

  • Check whether you have JDK installed; if not installed, Install
  • If JDK is installed, navigate into the bin folder of the installation, and try to execute javac.
  • If javac executes, proceed (+:
  • If javac does not execute, check your system path, and java path, and return to 2 above!
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!