在 Windows 10 上从命令行运行 Java 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37947165/
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
Running java programs from the command line on Windows 10
提问by Treeno1
I'm trying to run a basic "Hello World" app from the command line on windows 10 using
我正在尝试从 Windows 10 上的命令行运行一个基本的“Hello World”应用程序
javac MyFirstProgram.java
but i receive
但我收到
'javac' is not recognised as an internal or external command, operable program or batch
naturally, the first thing i did was google the problem and many solutions were presented, tried a few but nothing worked, has anybody else experienced this?
自然,我做的第一件事就是用谷歌搜索问题并提出了许多解决方案,尝试了一些但没有任何效果,有没有其他人遇到过这种情况?
采纳答案by SaiKiran
Steps to fix this error in windows 10/8/7
在 Windows 10/8/7 中修复此错误的步骤
1.Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and copy the address.
1.在Windows上使用Windows资源管理器C:\Program Files\Java\jdk1.7.0_02\bin检查你的javac路径并复制地址。
2.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.
2.进入控制面板。环境变量和在var开头插入地址。路径后跟分号。即 C:\Program Files\Java\jdk1.7.0_02\bin; . 不要删除现有的路径,只需单击并转到左端并粘贴上面的行。不要尝试其他任何东西,因为您只需要将代码链接到“javac.exe”,然后找到它。
3.Close your command prompt and reopen it,and write the code for compile and execution.
回答by ManoDestra
You need to add the location of your JDK to your PATH variable, if you wish to call javac.exe without the path.
如果您希望在没有路径的情况下调用 javac.exe,您需要将 JDK 的位置添加到您的 PATH 变量中。
set PATH=%PATH%;C:\path\to\your\JDK\bin\dir
Then...
然后...
javac.exe MyFirstProgram.java
OR, you can simply call it via the full path to javac.exe from your JDK installation e.g.
或者,您可以简单地通过 JDK 安装中 javac.exe 的完整路径调用它,例如
C:\path\to\your\JDK\bin\javac.exe MyFirstProgram.java