How to downgrade JDK?
Asked Answered
E

2

5

Currently my Java version is 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. I guess I need to downgrade to JDK 11.

Java Platform, Standard Edition 11 Reference Implementations is the only place I can get JDK 11. However it seems to be a binary, not a setup. Checking C:\Program Files\Java I found a folder for jdk-17 and jre1.8.0, so I copy the folder jdk-11 I just download to there. Checking the path environment I see these two lines:

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

Checking the javapath for 64-bit I see that there are java.exe, javac.exe, javaw.exe, jshell.exe. Does that mean that I should replace those files with the ones from jdk-11?

Edmonds answered 5/10, 2021 at 8:32 Comment(1)
The difference between JDK 11 and JDK 17 is that you can not enable such illegal access using the option --illegal-access=permit anymore. However, you could still make the access possible using --add-opens java.base/java.nio=ALL-UNNAMED, without the need to switch to an older JDK. Of course, in the long term, there will be no cure for software whose vendors insist on doing illegal accesses even after they learned about the encapsulation goal.Mathias
E
8
  1. Create new custom variable that point to the preferred version

  2. Set %JAVA_HOME%/bin as first entry to Path Variable

  3. Profit!

    Check with 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.

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

Edmonds answered 5/10, 2021 at 8:32 Comment(4)
Please make it clear in your question/answer what this refers to. Is it a specific OS? A specific IDE?Mathilda
this is on Windows, but I don't think it's specific to an IDEEdmonds
Also, you should bear in mind that this will set the environment variable across the whole system, so it may unintentionally downgrade the Java version for other things. This answer suggests setting the variable in the neo4j startup script instead, so it only applies to neo4j.Mathilda
I didn't know that. Many thanksEdmonds
H
1

For linux users run command sudo update-alternatives --config java it will return the list of java JDKs you have and you can simply use its index to select your preferred version

Halloran answered 18/12, 2023 at 8:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.