3

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?

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • 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. – Holger Oct 05 '21 at 14:28

1 Answers1

6
  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

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • 2
    Please make it clear in your question/answer what this refers to. Is it a specific OS? A specific IDE? – Andy Turner Oct 05 '21 at 08:38
  • this is on Windows, but I don't think it's specific to an IDE – Ooker Oct 05 '21 at 08:39
  • 2
    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](https://stackoverflow.com/questions/22113390/choose-a-specific-java-version-for-neo4j-or-cocoon) suggests setting the variable in the neo4j startup script instead, so it only applies to neo4j. – Andy Turner Oct 05 '21 at 08:42
  • I didn't know that. Many thanks – Ooker Oct 05 '21 at 08:46