Java is a very popular programming language which provides a different component in order to run, develop Java applications. JRE or Java Runtime Environment is used to run Java application. JDK or Java Development Kit is used to develop Java applications. In this tutorial, we will learn how to set up Java, JRE, and JDK operating system path variables in order to work properly.
Java是一种非常流行的编程语言,它提供了不同的组件来运行,开发Java应用程序。 JRE或Java Runtime Environment用于运行Java应用程序。 JDK或Java开发工具包用于开发Java应用程序。 在本教程中,我们将学习如何设置Java,JRE和JDK操作系统路径变量以使其正常工作。
找到JRE或JDK路径 (Locate JRE or JDK Path)
Before starting the configuration we have to locate the JRE or JDK path. JRE or JDK generally installed on the Program Files
or Program Files(x86)
directory under the Java directory like below.
在开始配置之前,我们必须找到JRE或JDK路径。 JRE或JDK通常安装在Java目录下的Program Files
或Program Files(x86)
目录下,如下所示。
![Locate JRE or JDK Path](https://i-blog.csdnimg.cn/blog_migrate/5536de7914133ff0c4a8c439c722165d.png)
and under the Java
directory the JDK is residing.
JDK驻留在Java
目录下。
![Locate JRE or JDK Path](https://i-blog.csdnimg.cn/blog_migrate/a01e50fab19f4252b9834e029604aa2c.png)
设置Java HOME_PATH环境变量(Set Java HOME_PATH Environment Variable)
Now we have learned the path of the Java, JRE or JDK installation. We can set this path as Java HOME_PATH environment variable. We will open the computer properties with by running sysdm.cpl
in the Run menu like below. We can also open it from the File Explorer -> Computer -> Right Click.
现在,我们已经了解了Java,JRE或JDK安装的路径。 我们可以将此路径设置为Java HOME_PATH环境变量。 我们将通过在“运行”菜单中运行sysdm.cpl
来打开计算机属性,如下所示。 我们也可以从文件资源管理器->计算机->右键单击打开它。
![Open System Properties](https://i-blog.csdnimg.cn/blog_migrate/7405a2c5ca42c9c2c69299b83bb723bd.png)
In the system properties, we will navigate to the Advanced
tab which provides the Environment Variables
button like below.
在系统属性中,我们将导航到“ Advanced
选项卡,其中提供了“ Environment Variables
按钮,如下所示。
![Open Environment Variables](https://i-blog.csdnimg.cn/blog_migrate/ec46fb6f26c1263e72d0c569b287e712.png)
Below we can see the environment variables menu where we will create the JAVA_HOME
system variable and set the path accordingly. We click to the New
in order to create a new system variable.
在下面我们可以看到环境变量菜单,在该菜单中我们将创建JAVA_HOME
系统变量并相应地设置路径。 我们单击“ New
以创建一个新的系统变量。
![Create New System Variable](https://i-blog.csdnimg.cn/blog_migrate/488d1eefed668167231f1f979b0ac8f0.png)
Here we will set the Variable Name
as JAVA_HOME
and the Variable Value
the path or Java, JRE or JDK which is C:\Program Files\Java\jdk-12
in this example. Then we will click OK.
在此示例中,我们将Variable Name
设置为JAVA_HOME
, Variable Value
为路径或Java,JRE或JDK,在此示例中为C:\Program Files\Java\jdk-12
。 然后,我们将单击“确定”。
![Set System Variable Name and Value](https://i-blog.csdnimg.cn/blog_migrate/ba89911a07e971500ab50c6c841c6a24.png)
设置JAVA可执行路径(Set JAVA Executable Path)
If we want to run java.exe
or similar executables provided by JRE or JDK we have to add the path of Java in the Path
variable like below. We select the system variable named Path
and click to the Edit
.
如果我们要运行JRE或JDK提供的java.exe
或类似的可执行文件,我们必须在如下所示的Path
变量中添加Java的Path
。 我们选择名为Path
的系统变量,然后单击Edit
。
![Edit Path System Variable](https://i-blog.csdnimg.cn/blog_migrate/c0968f2e224b4f8f76db172e26acf265.png)
Here we click to New
which will add a new line to the existing values.
在这里,我们单击“ New
,这将向现有值添加新行。
![](https://i-blog.csdnimg.cn/blog_migrate/ac5149e5c1d24d9ddbcddf87ca58058f.png)
Here we will set the bin
folder path which is C:\Program Files\Java\jdk-12\bin
in this example.
在此示例中,我们将设置bin
文件夹路径,该路径为C:\Program Files\Java\jdk-12\bin
。
![Add Path System Variable](https://i-blog.csdnimg.cn/blog_migrate/4a0f36de8ea053b4b3cbca6e134180e5.png)
Then we will click OK
and OK
in the environment variables screen which will save and activated new path configuration.
然后,我们将在环境变量屏幕中单击OK
和OK
,这将保存并激活新的路径配置。
检查Java是否正常工作 (Check Java Is Working)
We can check the new path configuration simply opening a new command line interface MS-DOS. Then just type java -version
which will execute java.exe
with the -version
option. We can see the current java binary version by running it.
我们只需打开新的命令行界面MS-DOS就可以检查新的路径配置。 然后只需键入java -version
使用-version
选项执行java.exe
。 通过运行它,我们可以看到当前的Java二进制版本。
![](https://i-blog.csdnimg.cn/blog_migrate/7eb5dac77dc95ea2d31adc259687de13.png)
翻译自: https://www.poftut.com/how-to-set-java-jre-and-jdk-home-path-and-environment-variables-on-windows/