javac 在 Windows 命令提示符下不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1678520/
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
javac not working in windows command prompt
提问by Domenic
I'm trying to use javac
with the windows command prompt, but it's not working.
我正在尝试javac
与 windows 命令提示符一起使用,但它不起作用。
After adding the directory "C:\Program Files\Java\jdk1.6.0_16\bin\"
to the end of the PATH
environment variable, the java
command works fine, but using javac
gives me the following error:
将目录添加"C:\Program Files\Java\jdk1.6.0_16\bin\"
到PATH
环境变量的末尾后,该java
命令工作正常,但使用时javac
出现以下错误:
'javac' is not recognized as an internal or external command, operable program or batch file.
'javac' 不是内部或外部命令,也不是可运行的程序或批处理文件。
采纳答案by paxdiablo
If you added it in the control panel while your command prompt was open, that won't affect your current command prompt. You'll need to exit and re-open or simply do:
如果您在命令提示符打开时将其添加到控制面板中,则不会影响您当前的命令提示符。您需要退出并重新打开或只需执行以下操作:
set "path=%path%;c:\program files\java\jdk1.6.0_16\bin"
By way of checking, execute:
通过检查,执行:
echo %path%
from your command prompt and let us know what it is.
从您的命令提示符并让我们知道它是什么。
Otherwise, make sure there isa javac in that directory by trying:
否则,请确保是在试图通过该目录的javac:
"c:\program files\java\jdk1.6.0_16\bin\javac.exe"
from the command prompt. You can also tell whichexecutable (if any) is being used with the command:
从命令提示符。您还可以通过命令判断正在使用哪个可执行文件(如果有):
for %i in (javac.exe) do @echo %~$PATH:i
This is a neat trick similar to the which
and/or whence
commands in some UNIX-type operating systems.
这是一个巧妙的技巧,类似于某些 UNIX 类型操作系统中的which
和/或whence
命令。
回答by valli
Give it as "C:\Program Files\Java\jdk1.6.0_16\bin". Remove the backslash it will work
将其指定为“C:\Program Files\Java\jdk1.6.0_16\bin”。删除反斜杠它会起作用
回答by Ryan Summey
I just had to do this to get this to work on windows 7 64.
我只需要这样做才能使其在 Windows 7 64 上运行。
Open up a command prompt (cmd.exe) and type:
打开命令提示符 (cmd.exe) 并键入:
set CLASSPATH=C:\Program Files\Java\jdk1.7.0_01\bin
Make sure you reopen all running command prompt Windows to get the environment variable updated as well.
确保重新打开所有正在运行的命令提示符 Windows 以更新环境变量。
回答by Sam
I know this may not be your specific error, but I once had a leading space in my path and java would work but javac would not.
我知道这可能不是您的具体错误,但是我的路径中曾经有一个前导空格,并且 java 可以工作,但 javac 不行。
For what it's worth, I offer the sage advice: "Examine your Path closely".
对于它的价值,我提供了明智的建议:“仔细检查你的道路”。
回答by mike
Windows OS searches the current directory and the directories listed in the PATH environment variable for executable programs. JDK's programs (such as Java compiler javac.exe and Java runtime java.exe) reside in directory "\bin" (where denotes the JDK installed directory, e.g., C:\Program Files\Java\jdk1.8.0_xx). You need to include the "\bin" directory in the PATH.
Windows 操作系统在当前目录和 PATH 环境变量中列出的目录中搜索可执行程序。JDK 的程序(如Java 编译器javac.exe 和Java 运行时java.exe)位于目录“\bin”(其中表示JDK 安装目录,例如C:\Program Files\Java\jdk1.8.0_xx)。您需要在 PATH 中包含“\bin”目录。
To edit the PATH environment variable in Windows XP/Vista/7/8:
在 Windows XP/Vista/7/8 中编辑 PATH 环境变量:
Control Panel ? System ? Advanced system settings
Switch to "Advanced" tab ? Environment Variables
In "System Variables", scroll down to select "PATH" ? Edit
控制面板 ?系统 ?高级系统设置
切换到“高级”选项卡?环境变量
在“系统变量”中,向下滚动以选择“PATH”?编辑
(( now read the following 3 times before proceeding, THERE IS NO UNDO))
((现在在继续之前阅读以下 3 遍,没有撤消))
In "Variable value" field, INSERT "c:\Program Files\Java\jdk1.8.0_xx\bin" (Replace xx with the upgrade number and VERIFY that this is your JDK's binary directory!!!) IN FRONT of all the existing directories, followed by a semi-colon (;) which separates the JDK's binary directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.
在“变量值”字段中,在所有现有文件的前面插入“c:\Program Files\Java\jdk1.8.0_xx\bin”(用升级号替换 xx 并验证这是您的 JDK 的二进制目录!!!)目录,后跟一个分号 (;),它将 JDK 的二进制目录与现有目录的其余部分分开。请勿删除任何现有条目;否则,某些现有应用程序可能无法运行。
Variable name : PATH
Variable value : c:\Program Files\Java\jdk1.8.0_xx\bin;[existing entries...]
回答by Someone
When i tried to make the .java to .class the command Javac didnt work. I got it working by going to C:\Program Files (x86)\Java\jdk1.7.0_04\bin and when i was on that directory I typed Javac.exe C\Test\test.java and it made the class with that tactic. Try that out.
当我尝试将 .java 变为 .class 时,命令 Javac 不起作用。我通过转到 C:\Program Files (x86)\Java\jdk1.7.0_04\bin 让它工作,当我在那个目录上时,我输入了 Javac.exe C\Test\test.java 并用它创建了类战术。试试看。
回答by Sundararajan wasuvan
";C:\Program Files\Java\jdk1.6.0\bin" sometime you may forget to put semicolon on last existing path.
";C:\Program Files\Java\jdk1.6.0\bin" 有时您可能会忘记在最后一个现有路径上放置分号。
回答by Malay Desai
Okay this can not be the case always but many of us have done this mistake in the past and few out of those are still not aware of it, which is, every time you append a path (any path) of any environment variable, you're likely to hit the space bar right after the "semicolon" (as you normally would, after the "period" while typing in an editor).
好吧,情况并非总是如此,但我们中的许多人过去都犯过这个错误,其中很少有人仍然没有意识到这一点,也就是说,每次附加任何环境变量的路径(任何路径)时,您' 很可能会在“分号”之后立即按下空格键(就像您通常在编辑器中键入时在“句点”之后一样)。
This will create a leading space in the path e.g " C:\Program Files\Java\jdk1.6.0\bin" and therefore "javac.exe" won't be found by the system.
这将在路径中创建一个前导空格,例如“C:\Program Files\Java\jdk1.6.0\bin”,因此系统将找不到“javac.exe”。
回答by Jason
Try the solutions here: http://techdem.centerkey.com/2009/05/javahome-command-script.html
在这里尝试解决方案:http: //techdem.centerkey.com/2009/05/javahome-command-script.html
These are much more robust to change -- like when you upgrade the JDK or JRE, since there is no hard coded path.
这些更改更加健壮——就像升级 JDK 或 JRE 时一样,因为没有硬编码路径。
The quick solution (if you don't want to read the blog) is
快速解决方案(如果您不想阅读博客)是
C:\>for /d %i in ("\Program Files\Java\jdk*") do set JAVA_HOME=%i
C:\>set PATH=%PATH%;%JAVA_HOME%
You can then add these lines to a startup/login script.
然后,您可以将这些行添加到启动/登录脚本中。
回答by TechDog
After a long Google, I came to know that javac.exe will be inside JDK(C:\Program Files\Java\jdk(version number)\bin) not inside JRE(C:\Program Files (x86)\Java\jre7\bin) "JRE doesn't come with a compiler. It(JRE) is simply a java runtime environment. What you need is the Java development kit."in order to use compiler javac
经过长时间的谷歌,我开始知道 javac.exe 将在JDK(C:\Program Files\Java\jdk(version number)\bin) 内而不是在JRE(C:\Program Files (x86)\Java\jre7 \bin) “JRE 不带有编译器。它(JRE)只是一个 Java 运行时环境。您需要的是 Java 开发工具包。” 为了使用编译器 javac
javac will not work if you are pointing bin inside jre
如果您将 bin 指向 jre,则 javac 将不起作用
In order to use javac in cmd , JDK must be installed in your system...
为了在 cmd 中使用 javac ,必须在您的系统中安装 JDK ...
For javac path
对于 javac 路径
path = C:\Program Files (x86)\Java\jre7\binthis is wrong
path = C:\Program Files (x86)\Java\jre7\bin这是错误的
path = C:\Program Files\Java\jdk(version number)\binthis is correct
path = C:\Program Files\Java\jdk(version number)\bin这是正确的
Make sure that "javac.exe" is inside your "C:\Program Files\Java\jdk(version number)\bin"
确保“javac.exe”在你的“C:\Program Files\Java\jdk(version number)\bin”中
Don't get confused with JRE and JDK both are totally different
不要混淆 JRE 和 JDK 两者完全不同
if you don't have JDK pls download from this link
如果您没有 JDK 请从此链接下载
or
或者
http://www.oracle.com/technetwork/java/javase/downloads/index.html
http://www.oracle.com/technetwork/java/javase/downloads/index.html
reference thread for JDK VS JRE What is the difference between JDK and JRE?
JDK VS JRE 的参考线程 JDK 和 JRE 有什么区别?