简体   繁体   English

设置类路径。 javac无法识别

[英]setting up classpath. javac is not recognized

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. 我读了一篇关于设置类路径的文章,但是我得到一个错误,即javac不被识别为内部或外部命令。 What should I do? 我该怎么办? (I dont want to set a permanent CLASSPATH) This is what I have done in my command line (我不想设置永久CLASSPATH)这是我在命令行中所做的

D:\user> set path=%path%;C:\Program Files\Java\1.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 谢谢

Assuming that the PATH is correct 1 , the most likely cause is that you have a JRE installation ... and a JRE doesn't include a java compiler. 假设PATH正确1 ,最可能的原因是您安装了JRE ......并且JRE不包含Java编译器。 You need a JDK installation if you want to compile from the command line. 如果要从命令行进行编译,则需要安装JDK。

(You can confirm this by looking in the C:\\Program Files\\Java\\1.7.0_07\\bin directory to see if it contains a javac.exe file. 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; 您需要下载一个JDK安装程序; see http://www.oracle.com/technetwork/java/javase/downloads/index.html 请参阅http://www.oracle.com/technetwork/java/javase/downloads/index.html


1 - I don't think quotes are required in a PATH variable on Windows. 1 - 我不认为Windows上的PATH变量需要引号。 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 ... 但我从未真正理解Windows中引用的逻辑......

Better do it in Environmental variable and check it! 最好在环境变量中进行检查并检查它!

在此输入图像描述

Its an issue related to Program Files . 这是一个与Program Files相关的问题。

First make sure that your JDK Folder is installed in Program Files or Program Files(x86) or any other folder. 首先确保您的JDK文件夹安装在Program FilesProgram Files(x86)或任何其他文件夹中。

Then you should use the path of bin folder in " ". 然后你应该在“”中使用bin文件夹的路径。 Because command prompt does break the string at space. 因为命令提示符会破坏空格中的字符串。 When you will write it in " " then it will take is as a whole String. 当你用“”写它时,它将作为一个整体字符串。

You try these commands 你尝试这些命令

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

or 要么

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

It might help you to get out of this. 它可能会帮助你摆脱这种局面。

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

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\\bin AND HIT ENTER that's it. TYPE IN C:\\ Program Files \\ Java \\ jdk1.6.0 \\ bin AND HIT ENTER就是这样。

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

Adding few more information to this: 添加更多信息到这个:

Please check the version of JDK and JRE installed on your computer. 请检查计算机上安装的JDK和JRE的版本。 Recently I faced the same problem even after setting the PATH. 最近我在设置PATH后面临同样的问题。 It gives the error "javac - command is not recognised" 它给出错误“javac - 命令无法识别”

Solution is there must be similar versions of JDK as well as JRE 解决方案是必须有类似的JDK版本以及JRE

Eg: JDK 1.7.75 along with JRE 1.7.75 例如:JDK 1.7.75以及JRE 1.7.75

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

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