Install different versions of JDK on a physical machine (including classpath related issues)

         When we need to use different versions of JDK on a physical machine, installing and freely switching different versions of JDK becomes a skill we need to master.

One: The specific steps of installation

1: Download the different versions of JDK required and place them on the physical machine. (eg: D:\JAVA\JDK)

2: Name the different versions of JDK separately and place them in D:\JAVA\JDK

  1. jdk_1.8: D:\JAVA\JDK\jdk_1.8
  2. jdk_1.11  D:\JAVA\JDK\jdk_1.11

Note : Here the author suggests that the type of JDK needs to be unified. Both jdk8 and jdk11 use the decompressed version. If you use the installed version, you need to copy the java.exe, javaw.exe, java.exe, javaw.exe , There are three javaws.exe files, because this involves the issue of execution priority, (the priority of the C:\Windows\System32 directory is higher than that of the JAVA_HOME configuration directory, and there may be problems that may cause JDK version switching to not take effect. )

3 : Configure environment variables

  1. jdk_1.8  

Configure the JAVA_HOME variable: variable name: JAVA_HOME8 variable value: \JAVA\JDK\jdk_1.8

Configure the path variable: \JAVA\JDK\jdk_1.8\bin

(2)jdk_1.11

Configure the JAVA_HOME variable: variable name: JAVA_HOME11 variable value: \JAVA\JDK\jdk_1.11

Configure the path variable: \JAVA\JDK\jdk_1.11\bin

(4) The most important step ( related to free switching of JDK versions): Since the execution priority of environment variables is from top to bottom (from left to right, from front to back), when setting the JAVA_HOME variable: set a variable name For: JAVA_HOME variable value: %JAVA_HOME% and placed before JAVA_HOME8 and JAVA_HOME11.

If you need to execute JDK8, change the variable value in JAVA_HOME to "%JAVA_HOME8"

If you need to execute JDK11, change the variable value in JAVA_HOME to "%JAVA_HOME11"

Two: Questions about configuring classpath

The translation of classpath is the class path, which is an environment variable value to be set in the Java environment variable configuration, which is the path of the .class file , indicating where the JVM needs to find the class file to run. The configured classpath loads classes . When many students search and configure JDK environment variables, most of the blog posts require classpath to be configured, but some students say that they have not configured classpath, but only configured the JAVE_HOME and path variables in the environment variables, and the program is still running normally.

For this question, I consulted the official documents, and the answer I got was: after JDK1.5, classpath is not a necessary configuration; before JDK1.5, because the class cannot be loaded in the current directory (neither lib The .jar file in the folder), so you need to configure the classpath. But after JDK1.5, JRE can automatically search the class files in the directory and load the classes of dt.jar and tool.jar. But if you are using a version earlier than JDK1.5, you need to configure the classpath without hesitation.

Classpath related explanation:

Location: .;%Java_Home%\bin;%Java_Home%\lib\dt.jar;%Java_Home%\lib\tools.jar

  1. . Indicates the current path.

(2) JAVA_HOME: represents the path of the JDK file.

(3); Indicates that there are multiple executable class file directories, separated by;

(4) dt.jar is a class library about the operating environment, mainly used for swing packages, if not used, it does not need to be configured.

(5) tools.jar is a tool library

Guess you like

Origin blog.csdn.net/weixin_49769267/article/details/131566978