java 无法识别 javac

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1299750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:01:40  来源:igfitidea点击:

javac not recognized

javapathjavac

提问by Nate

What can I do when I keep receiving the error

当我不断收到错误时我该怎么办

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

'javac' 不是内部或外部命令,也不是可运行的程序或批处理文件

when I want to compile my jar or .classfile?

当我想编译我的 jar 或.class文件时?

Thanks

谢谢

回答by Nate

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

确保 %JAVA_HOME%/bin 在您的 %PATH% 上(或 $JAVA_HOME 在 *nix 中的 $PATH 上)。

回答by DaveJohnston

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.

1)在调用之前切换到javac所在的目录。

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

2) 调用时使用 javac 的完整路径,例如 C:\java\jdk1.6.0_12\bin\javac ...

3) Add the javac directory to the PATH environment variable

3)将javac目录添加到PATH环境变量中

回答by yalestar

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

这只是意味着 javac 不在您的 PATH 变量中。

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

在 Windows 上,您只需将包含 javac.exe 的文件夹添加到 PATH 环境变量 (Win+Pause/Break)。

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

在 Linux/Mac/Unix 上,只需将该目录附加到 .bashrc 或类似文件中的 $PATH 。

回答by 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.

您看到的错误是由 Windows 生成的,并非特定于 Java。该错误意味着您键入了一个命令,而 Windows 找不到该名称的命令。

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

纠正这种情况的最简单方法是确保 Java 正确安装在您系统的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_HOMEand point it at the base install directory for the version of Java that you installed.

首先,确保您安装了 JDK(而不仅仅是 JRE)。您的下一个最佳选择是添加一个名为的环境变量,JAVA_HOME并将其指向您安装的 Java 版本的基本安装目录。

Next, modify your PATHenvironment 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 javacis in there (along with a number of other Java development tools).

接下来,PATH通过将字符串添加%JAVA_HOME%\bin;PATH. 如果您查看该目录的内容,您会看到它javac在那里(以及许多其他 Java 开发工具)。

回答by Joonas Pulakka

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

您必须安装 JDK(包括 javac 编译器)并确保它在路径中。见http://java.sun.com/javase/downloads/index.jsp

回答by Jesper

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

JDK 安装说明的第 4 步(更新 PATH 变量)解释了您应该执行的操作,以便您只需javac在命令提示符窗口中键入即可。

回答by user513365

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

下面的链接一步一步地解释了如何设置 java_home 和路径变量。 JAVA_HOME 设置

回答by Jozsef

Even if I had

即使我有

  • JDK installed
  • JAVA_HOMEdefined
  • %JAVA_HOME%\binpresent in my %PATH%
  • 安装了JDK
  • JAVA_HOME定义
  • %JAVA_HOME%\bin出现在我的 %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 javacin JAVA_HOME\binin this case.

我仍然有这个错误。我通过从我的路径变量中消除 JRE 来解决它。以前放过JAVA_HOME,没有javac。看来Windows无法找到javacJAVA_HOME\bin这种情况下。

回答by MIA

For Windows

对于 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 Newand 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]

变量值:C:\Program Files\Java\jdk1.7.0_45\bin [*确保这是适合您的路径]

Then it should work

那么它应该工作