“This is the fifth day of my participation in the First Challenge 2022. For details: First Challenge 2022.”


preface


First, the wrong scene rehearsal

I would like to upgrade JDK 8 to JDK 17 by compression package.

  • Local version: 1.8.0_251
  • Pre-upgrade version: 17.0.2

1.1. View the local version

Before configuring the environment variable, we need to make sure that the old version exists locally. If Java is not available locally, there will be no problem with java-version unchanged.

java -version
Copy the code

We can see the old version of the information, as shown below:

1.2 java-version invariance problem occurs

After the local decompression and configuration of JDK 17 are complete, the 1.8.0_251 version is still displayed instead of 17.0.2 when you enter Java -version.

There are many reasons for this problem, and we will examine them one by one.

Check whether the newly installed JDK is correctly configured

2.1. Download and unzip the target JDK

We unzip the target JDK we need to install into the target folder, as shown in my image below:

2.2. Configure Java environment variables

  • The JAVA_HOME variable points to the JDK root directory, one level above the bin directory.
  • The PATH variable points to the BIN directory of the JDK.

You can configure JAVA_HOME and PATH respectively in Browse Directory mode, as shown in the following figure:

2.3. Note the order of the PATH variables

The PATH variable configured in the environment variable is read by the system in sequence and should be placed at the top.

There are ordering issues, and there are cases where java-version does not change. The order can be changed by the “move up” button on the right of the image above.

2.4. View the Java version information

Normally, you can enter Java -version on the command line to view the version information of the newly installed Java.

However, if we can see that the old version information is still displayed instead of the new version information, we need to go to the specific scenario to further analyze the cause of the error, as shown in the following figure:

Analysis of different specific error scenarios

I’ve grouped them into the following categories in order of the most common error scenarios, but if you can’t solve it, look at the next one.

3.1. PATH variable order error solution

This problem is the most common one, and was addressed in 2.3.

Cause: The system reads the PATH variable configured in the environment variable in sequence. If the system reads the Java PATH with insufficient priority, the previous version information is still displayed. It should be placed at the top according to priority.

Solution: Change the order of the Java bin directory by clicking the “Move up” button on the right, as shown below:

3.2 The old java.exe solution exists in the system

Error cause: If the system disk shortcut call contains the previous java.exe, such as JDK 1.8.0_251 java.exe, the system will call the latest java.exe first, and the old java-version is displayed.

Solution: Use the search tool to search for the java.exe file on the system disk (drive C) and delete the folder containing the java.exe file to avoid invoking the earlier version. The three java.exe files are in the javapath related directory of Oracle directory, as shown in the following figure. Delete the entire Oracle directory or Java directory.

Note: the java.exe file is only considered if it exists on the system disk. This is the output file of the older JDK.

Description: Java. exe exists in the Java directory of Oracle directory. The author’s java.exe file is located in C:\Program Files (x86)\Common Files directory. There are also some friends in C:\Windows\System32 directory, through the search tool such as Everything easy to find.

Fourth, the problem is solved perfectly

Through the above steps, the problem is solved perfectly, and you can see the new version information by typing Java -version on the command line, as shown in the following figure:


conclusion


I am White Deer, a tireless programmer ape. Hope this article can be beneficial to you, welcome everyone’s one key three even! If you have any other questions, suggestions or additions, please leave a comment at the bottom of this article. Thank you for your support!