简体   繁体   English

Java环境变量

[英]Java Environment Variables

So I'm setting everything up to compile java on my Windows 10 computer, and when I went to the environment variables there was no existing PATH, so I added one. 所以我设置一切都在我的Windows 10计算机上编译java,当我去环境变量时没有现有的PATH,所以我添加了一个。 When I type "javac" in the command prompt it is able to recognize it, but when I try to save a java file (on notepad as a test) and try to put that in the command prompt I get the "is not recognized as an internal or external command, operable program or batch file." 当我在命令提示符下键入“javac”时,它能够识别它,但当我尝试保存一个java文件(在记事本上作为测试)并尝试将其放入命令提示符时,我得到“未被识别为内部或外部命令,可操作程序或批处理文件。“ Everything I've looked up about this response refers back to the environmental variables, but I can't figure out what I did wrong. 我所看到的关于这种反应的一切都回到了环境变量,但我无法弄清楚我做错了什么。 My PATH looks like this: C:\\Program Files\\Java\\jdk1.8.0_77\\bin. 我的PATH看起来像这样:C:\\ Program Files \\ Java \\ jdk1.8.0_77 \\ bin。 Am I missing something obvious? 我错过了一些明显的东西吗

环境变量

Here you need to set two variables in the " Environment Variables " for executing Java files. 在这里,您需要在“环境变量”中设置两个变量来执行Java文件。 In the image you can see first variable(Java_Home) is defining the path of jdk in the system and the second variable is defining the path where the Java executables(javac.exe, java.exe, javadoc.exe, and so on) reside. 在图像中,您可以看到第一个变量(Java_Home)定义了系统中jdk的路径,第二个变量定义了Java可执行文件(javac.exe,java.exe,javadoc.exe等)所在的路径。 Do it like that your problem will be solved.... 这样做可以解决你的问题....

Based on the 'not recognized as internal or external command' message it is possible your PATH variable is not set up properly. 基于“未识别为内部或外部命令”消息,您的PATH变量可能未正确设置。 You need to add the full path to your JDK bin to the system PATH variable, in Control Panel, System, Advanced, Environment Variables. 您需要在控制面板,系统,高级,环境变量中将JDK bin的完整路径添加到系统PATH变量。 See https://docs.oracle.com/javase/tutorial/essential/environment/paths.html for details. 有关详细信息,请参阅https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

Though less likely to be the cause of the problem you describe, you also may need to set CLASSPATH. 虽然不太可能成为您描述的问题的原因,但您可能还需要设置CLASSPATH。 The PATH variable indicates where the executables reside (eg, javac.exe and java.exe). PATH变量指示可执行文件所在的位置(例如,javac.exe和java.exe)。 The CLASSPATH variable indicates where the class files reside. CLASSPATH变量指示类文件所在的位置。 The default CLASSPATH is the current working directory. 默认CLASSPATH是当前工作目录。 So if you are executing from the same directory where your class(es) reside(s), you do not need to specify it. 因此,如果您从类所在的同一目录执行,则无需指定它。

Run 'javac.exe yourprogram.java' to compile the program. 运行'javac.exe yourprogram.java'编译程序。 Then run 'java yourprogram' to execute it. 然后运行'java yourprogram'来执行它。

Just to clarify, you saved your java class , say 'Test.java' and tried to run it through command prompt by calling Test? 只是为了澄清,你保存了你的java类,说'Test.java'并尝试通过调用Test来通过命令提示符运行它? Can you explain what did you do exactly? 你能解释一下你到底做了什么吗?

You will need to compile the class using javac and run it using java . 您需要使用javac编译该类并使用java运行它。

If you have already installed a compatible JDK and JRE for your computer and wondering why your computer is not recognizing 'java' and 'javac' as an internal or external command you probably have not set up your environment variables properly. 如果您已经为计算机安装了兼容的JDK和JRE,并且想知道为什么您的计算机没有将'java'和'javac'识别为内部或外部命令,那么您可能没有正确设置环境变量。

Windows directions Windows方向

Go to Computer > C drive > Program Files > Java > JDK File 转到计算机> C盘>程序文件> Java> JDK文件

Right click on the path and click 'Edit Address'. 右键单击路径,然后单击“编辑地址”。 After you copy the address follow the steps below. 复制地址后,请按照以下步骤操作。

Go to Control Panel > System and Security > System > Advance system settings > environment variables 转至控制面板>系统和安全>系统>高级系统设置>环境变量

In the second column (System Variables), Click 'New...' 在第二列(系统变量)中,单击“新建...”

Set the 'Variable name' to JAVA_HOME 将“变量名称”设置为JAVA_HOME

Set the 'Variable value' to the what you recently copied then click 'Ok' 将“变量值”设置为您最近复制的内容,然后单击“确定”

In the same place you were (System variables), find the Variable 'Path' and click 'Edit...' 在同一个地方(系统变量),找到变量'路径'并点击'编辑...'

Under the 'Variable value', move your cursor all the way to the beginning and enter in %JAVA_HOME%\\bin; 在“变量值”下,将光标一直移到开头,然后输入%JAVA_HOME%\\ bin;

Click 'Ok' twice then right click directly on your desktop and click 'Refresh' 单击“确定”两次,然后直接在桌面上单击鼠标右键,然后单击“刷新”

Lastly, open your command prompt and type in the keywords 'java' and 'javac' 最后,打开命令提示符并输入关键字'java'和'javac'

I hoped this worked for most people. 我希望这适用于大多数人。 I have been trying to figure this out for about a week and I found a great solution that I just wanted to share. 我一直试图解决这个问题大约一个星期,我找到了一个很好的解决方案,我只想分享。

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

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