javac不能识别为内部或外部命令、可操作程序或批处理文件

时间:2021-02-10 23:13:51

I am new to the Java application and having trouble compiling a simple Helloworld program.

我是Java应用程序的新手,在编译一个简单的Helloworld程序时遇到了麻烦。

JDK 1.7.0 is installed in my Windows 7 and was able to set the path variable but didn't work, so I tried something but still keeps on giving me the same error. In my cmd it says this:

JDK 1.7.0安装在我的Windows 7中,能够设置path变量,但是不能工作,所以我尝试了一些东西,但是仍然继续给我同样的错误。在我的cmd中,它说

C:\Users\Ivy>cd \

C:\cd java files

C:\java files>set path=C:Program Files (x86)\Java\jdk1.7.0\bin

C:\java files>javac Hello.java
'javac' is not recognized as an internal or external command, operable program or batch file.

6 个解决方案

#1


302  

  • Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and copy the address.

    检查你的javac路径在Windows上使用Windows Explorer C:\Program Files\Java\ jdk1.7.0_02 \ bin并复制地址。

  • Go to Control Panel. Environment Variables and Insert the address at the beginning of var. Path followed by semicolon. i.e C:\Program Files\Java\jdk1.7.0_02\bin; . Do not delete the path existent, just click in and go to the left end and paste the line above. Do not try anything else, because you just need to link your code to "javac.exe" and you just need to locate it.

    去控制面板。环境变量,并在var. Path后面跟着分号的开头插入地址。我。e C:\Program Files\Java\ jdk1.7.0_02 \ bin。。不要删除已存在的路径,只需单击并进入左边并粘贴上面的行。不要尝试其他任何东西,因为您只需要将您的代码链接到“javac”。你只需要找到它。

  • Close your command prompt and reopen it,and write the code for compile and execution.

    关闭命令提示符并重新打开它,并编写编译和执行的代码。

#2


66  

try this.. I had it too but now it solved in XP..

试试这个. .我也有,但是现在它在XP中解决了。

C:\ YourFolder >set path=C:\Program Files\Java\jdk1.7.0_09\bin;
C:\ YourFolder >javac YourCode.java

#3


37  

Correct the path - you missed a backslash after C:

纠正路径-你错过了C后面的反斜杠:

C:\java files>set path=C:\Program Files (x86)\Java\jdk1.7.0\bin

#4


6  

Here write set Path="C:\Program Files\Java\jdk1.7.0_09\bin" or set PATH="C:\Program Files\Java\jdk1.7.0_09\bin"

这里写入set Path="C:\程序文件\Java\jdk1.7.0_09\bin"或set Path="C:\程序文件\Java\jdk1.7.0_09\bin"

Don't write path.

不要写路径。

you can also go without set.

你也可以不设置。

I have tried it works well.

我试过了,效果不错。

#5


5  

If java command is working and getting problem with javac. then first check in jdk's bin directory javac.exe file is there or not. If javac.exe file is exist then set JAVA_HOME as System variable.

如果java命令正在工作并在javac上出现问题。然后首先检查jdk的bin目录javac。exe文件是否存在。如果javac。exe文件存在,然后将JAVA_HOME设置为系统变量。

#6


2  

Check your environment variables.

检查你的环境变量。

In my case I had JAVA_HOME set in the System variables as well as in my User Account variables and the latter was set to a wrong version of Java. I also had the same problem with the Path variable.

在我的例子中,我在系统变量和用户帐户变量中都设置了JAVA_HOME,而后者被设置为错误的Java版本。路径变量也有同样的问题。

After deleting JAVA_HOME from my User Account variables and removing the wrong path from the Path variable it worked correctly.

在从我的用户帐户变量中删除JAVA_HOME并从path变量中删除错误的路径之后,它正确地工作了。

#1


302  

  • Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and copy the address.

    检查你的javac路径在Windows上使用Windows Explorer C:\Program Files\Java\ jdk1.7.0_02 \ bin并复制地址。

  • Go to Control Panel. Environment Variables and Insert the address at the beginning of var. Path followed by semicolon. i.e C:\Program Files\Java\jdk1.7.0_02\bin; . Do not delete the path existent, just click in and go to the left end and paste the line above. Do not try anything else, because you just need to link your code to "javac.exe" and you just need to locate it.

    去控制面板。环境变量,并在var. Path后面跟着分号的开头插入地址。我。e C:\Program Files\Java\ jdk1.7.0_02 \ bin。。不要删除已存在的路径,只需单击并进入左边并粘贴上面的行。不要尝试其他任何东西,因为您只需要将您的代码链接到“javac”。你只需要找到它。

  • Close your command prompt and reopen it,and write the code for compile and execution.

    关闭命令提示符并重新打开它,并编写编译和执行的代码。

#2


66  

try this.. I had it too but now it solved in XP..

试试这个. .我也有,但是现在它在XP中解决了。

C:\ YourFolder >set path=C:\Program Files\Java\jdk1.7.0_09\bin;
C:\ YourFolder >javac YourCode.java

#3


37  

Correct the path - you missed a backslash after C:

纠正路径-你错过了C后面的反斜杠:

C:\java files>set path=C:\Program Files (x86)\Java\jdk1.7.0\bin

#4


6  

Here write set Path="C:\Program Files\Java\jdk1.7.0_09\bin" or set PATH="C:\Program Files\Java\jdk1.7.0_09\bin"

这里写入set Path="C:\程序文件\Java\jdk1.7.0_09\bin"或set Path="C:\程序文件\Java\jdk1.7.0_09\bin"

Don't write path.

不要写路径。

you can also go without set.

你也可以不设置。

I have tried it works well.

我试过了,效果不错。

#5


5  

If java command is working and getting problem with javac. then first check in jdk's bin directory javac.exe file is there or not. If javac.exe file is exist then set JAVA_HOME as System variable.

如果java命令正在工作并在javac上出现问题。然后首先检查jdk的bin目录javac。exe文件是否存在。如果javac。exe文件存在,然后将JAVA_HOME设置为系统变量。

#6


2  

Check your environment variables.

检查你的环境变量。

In my case I had JAVA_HOME set in the System variables as well as in my User Account variables and the latter was set to a wrong version of Java. I also had the same problem with the Path variable.

在我的例子中,我在系统变量和用户帐户变量中都设置了JAVA_HOME,而后者被设置为错误的Java版本。路径变量也有同样的问题。

After deleting JAVA_HOME from my User Account variables and removing the wrong path from the Path variable it worked correctly.

在从我的用户帐户变量中删除JAVA_HOME并从path变量中删除错误的路径之后,它正确地工作了。