java 设置类路径。无法识别 javac

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12756611/
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-31 10:05:30  来源:igfitidea点击:

setting up classpath. javac is not recognized

javajavac

提问by kaboom

I am trying to run my java program from command line.

我正在尝试从命令行运行我的 java 程序。

I read an article about setting up classpath, but I get an error of javac is not recognized as internal or external command. What should I do? (I dont want to set a permanent CLASSPATH) This is what I have done in my command line

我读了一篇关于设置类路径的文章,但我收到了 javac 未被识别为内部或外部命令的错误。我该怎么办?(我不想设置永久的 CLASSPATH)这就是我在命令行中所做的

D:\user> set path=%path%;C:\Program Files\Java.7.0_07\bin

D:\user> cd testing

D:\user\testing> javac firstProgram.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

Thank you

谢谢

回答by Stephen C

Assuming that the PATH is correct1, the most likely cause is that you have a JRE installation ... and a JRE doesn't include a java compiler. You need a JDK installation if you want to compile from the command line.

假设 PATH 是正确的1,最可能的原因是您安装了 JRE ......而 JRE 不包含 java 编译器。如果要从命令行编译,则需要安装 JDK。

(You can confirm this by looking in the C:\Program Files\Java\1.7.0_07\bindirectory to see if it contains a javac.exefile. A JRE won't ...)

(您可以通过查看C:\Program Files\Java\1.7.0_07\bin目录以查看它是否包含javac.exe文件来确认这一点。JRE 不会......)

Where can I find the Java compiler to download..

我在哪里可以找到要下载的 Java 编译器..

You need to download one of the JDK installers; see http://www.oracle.com/technetwork/java/javase/downloads/index.html

您需要下载 JDK 安装程序之一;见http://www.oracle.com/technetwork/java/javase/downloads/index.html



1 - I don't think quotes are required in a PATH variable on Windows. At least that's what various examples that Google found for me seem to imply. But I've never really understood the logic behind quoting in Windows ...

1 - 我认为 Windows 上的 PATH 变量中不需要引号。至少谷歌为我找到的各种例子似乎暗示了这一点。但我从来没有真正理解在 Windows 中引用背后的逻辑......

回答by madhairsilence

Better do it in Environmental variable and check it!

最好在环境变量中做并检查它!

enter image description here

enter image description here

回答by MouseCrasher

Its an issue related to Program Files.

它是一个与Program Files相关的问题。

First make sure that your JDK Folder is installed in Program Filesor Program Files(x86)or any other folder.

首先确保您的 JDK 文件夹安装在Program FilesProgram Files(x86)或任何其他文件夹中。

Then you should use the path of bin folder in " ". Because command prompt does break the string at space. When you will write it in " " then it will take is as a whole String.

那么你应该使用“”中bin文件夹的路径。因为命令提示符确实会在空格处中断字符串。当你将它写在“”中时,它将作为一个完整的字符串。

You try these commands

你试试这些命令

set path=%path%;"C:\Program Files\Java.7.0_07\bin"

or

或者

set path=%path%;"C:\Program Files(x86)\Java.7.0_07\bin"

It might help you to get out of this.

它可能会帮助您摆脱困境。

回答by Satheesh Cheveri

try below command is recognized from command prompt C:\Program Files\Java\1.7.0_07\bin\javac ab.java

尝试从命令提示符 C:\Program Files\Java\1.7.0_07\bin\javac ab.java 识别以下命令

This is just to verify your javac

这只是为了验证您的 javac

回答by user2038944

Here's how you can set the path temporary, meaning if you close and reopen "command prompt" you will have to set the path again.

这是临时设置路径的方法,这意味着如果关闭并重新打开“命令提示符”,则必须再次设置路径。

Assuming the path is C:\Program Files\Java\jdk1.6.0\bin

假设路径是 C:\Program Files\Java\jdk1.6.0\bin

TYPE IN C:\Program Files\Java\jdk1.6.0\binAND HIT ENTER that's it.

输入 C:\Program Files\Java\jdk1.6.0\bin并按回车键。

回答by Duc Tran

The commands D:\user> set path=%path%;C:\Program Files\Java\1.7.0_07\binworks well for me

这些命令D:\user> set path=%path%;C:\Program Files\Java\1.7.0_07\bin对我来说效果很好

回答by adhoc

Adding few more information to this:

对此添加更多信息:

Please check the version of JDK and JRE installed on your computer. Recently I faced the same problem even after setting the PATH. It gives the error "javac - command is not recognised"

请检查您计算机上安装的 JDK 和 JRE 的版本。最近,即使设置了 PATH,我也遇到了同样的问题。它给出了错误“javac - 命令无法识别”

Solution is there must be similar versions of JDK as well as JRE

解决办法是必须有类似版本的JDK和JRE

E.g.: JDK 1.7.75 along with JRE 1.7.75

例如:JDK 1.7.75 和 JRE 1.7.75