简体   繁体   English

javac不承认

[英]javac not recognized

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 .class file? 当我想编译我的jar或.class文件?

Thanks 谢谢

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

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, eg 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环境变量中

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中。

The error that you are seeing is generated by Windows, and isn't specific to Java. 您看到的错误是由Windows生成的,并不是特定于Java的。 That error means that you typed a command and Windows could not find the command by that name. 该错误意味着您键入了一个命令,Windows无法通过该名称找到该命令。

The easiest way of rectifying the situation is to ensure that Java is properly installed in your system's PATH . 纠正这种情况的最简单方法是确保在系统的PATH正确安装Java。

First, ensure that you have a JDK installed (and not just a JRE). 首先,确保安装了JDK(而不仅仅是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. 您最好的选择是添加一个名为JAVA_HOME的环境变量,并将其指向您安装的Java版本的基本安装目录。

Next, modify your PATH environment variable by prepending the string %JAVA_HOME%\\bin; 接下来,通过在字符串%JAVA_HOME%\\bin;之前添加字符串来修改PATH环境变量%JAVA_HOME%\\bin; to whatever is already in your PATH . 到已经在你的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). 如果你查看该目录的内容,你会看到javac在那里(以及许多其他Java开发工具)。

You have to install JDK (which includes javac compiler) and ensure that it's in the path. 您必须安装JDK(包括javac编译器)并确保它在路径中。 See http://java.sun.com/javase/downloads/index.jsp 请参阅http://java.sun.com/javase/downloads/index.jsp

Even if I had 即使我有

  • JDK installed JDK已安装
  • JAVA_HOME defined JAVA_HOME定义
  • %JAVA_HOME%\\bin present in my %PATH% 我的%PATH%存在%JAVA_HOME%\\bin

I still had this error. 我仍然有这个错误。 I resolved it by eliminating the JRE from my path variable. 我通过从路径变量中删除JRE来解决它。 It was put before JAVA_HOME , has no javac . 它放在JAVA_HOME之前,没有javac It seems Windows can't find javac in JAVA_HOME\\bin in this case. 在这种情况下,似乎Windows无法在JAVA_HOME\\bin中找到javac

JDK安装说明的步骤4(更新PATH变量)说明了应该做什么,以便您只需在命令提示符窗口中键入javac即可。

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 New and add enter information below 控制面板 > 系统 ...然后单击高级系统设置 (左窗格)...然后将打开弹出窗口...然后单击环境变量 ...然后将打开另一个窗口...单击新建并在下面添加输入信息

Variable name : PATH 变量名称 :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 然后它应该工作

The link below gives a step by step explanation on how to set up java_home and path variables. 下面的链接提供了有关如何设置java_home和路径变量的分步说明。 JAVA_HOME setup JAVA_HOME设置

  • Check whether you have JDK installed; 检查是否安装了JDK; if not installed, Install 如果没有安装,请安装
  • If JDK is installed, navigate into the bin folder of the installation, and try to execute javac. 如果安装了JDK,请导航到安装的bin文件夹,然后尝试执行javac。
  • If javac executes, proceed (+: 如果javac执行,继续(+:
  • If javac does not execute, check your system path, and java path, and return to 2 above! 如果javac没有执行,请检查系统路径和java路径,并返回上面的2!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM