如何降级JDK?

How to downgrade JDK?

目前我的 Java 版本是 17。Neo4j requires me to install Java 11 or OpenJDK 11, or else it will give the error java.lang.IllegalAccessException: module java.base does not open java.nio to unnamed module @1817d444。我想我需要降级到 JDK 11.

Java Platform, Standard Edition 11 Reference Implementations 是我唯一可以获得 JDK 11 的地方。但是它似乎是一个二进制文件,而不是一个设置。检查 C:\Program Files\Java 我找到了 jdk-17 和 jre1.8.0 的文件夹,所以我将文件夹 jdk-11 复制到那里。检查路径环境我看到这两行:

C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

检查 64 位的 javapath 我看到有 java.exe、javac.exe、javaw.exe、jshell.exe。这是否意味着我应该用 jdk-11 中的文件替换这些文件?

  1. 创建指向首选版本的新自定义变量

  2. 将 %JAVA_HOME%/bin 设置为路径变量的第一个条目

  3. 盈利!

    检查java -version

Why not just remove the Oracle Java path entry and not worry about your JAVA_HOME placement in the Path?

You might suggest to simply remove the Oracle Java path that was prepended to your Windows PATH by the installer. Yes, I thought of that too, but the installer also copies the java.exe, javaw.exe, and javaws.exe files to C:\Windows\System32 directory, which is also in the Windows PATH variable. So rather than chase down all the possible directories that the installer put Java, and to avoid deleting the System32 files that actually may be necessary to some process somewhere, I decided that simply prepending my preferred Java Home directory to the path was best option.

来源:How to set custom Java path after installing JDK 8 – Douglas C. Ayers