Search code examples
javaeclipsesdkjava-17

Java code not recognized, Eclipse error: "Target is not a JDK Root. Java executable was not found"


Problem: Eclipse is not recognizing my Java code on my Mac (e.g., the main method, String, Object class... none of that is recognized; the pre-built Java classes aren't even there!).

Detail: I have the latest Eclipse (2022-09) and even tried 2022-06. I also have the latest Java version (terminal: "java -version" brings 17.0.4.1). In Eclipse settings, I see the following (see PINK for how I got to these settings, see YELLOW for problem): enter image description hereenter image description here

But I have the following in Finder:

enter image description here

So maybe the JavaSE/SDK file did not get imported auotmatically. So then I manually try to do that (see PINK), but when I select any of the JavaSE/JDK files from Finder, this happens (YELLOW):

enter image description here

Is there any resolution? Thanks!

Note: Java 17 and Eclipse are both mandatory for my college class. In fact, for the current project, only Java 17 is compatible with the .jars file we need to work with, so there's no other choice.


Solution

  • The correct path for Java on macOS is the Contents/Home folder in the xxx.jdk

    So in the "Installed JREs" you should have something like:

    /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
    

    or

    /Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
    

    As mentioned in the comments running the command

    /usr/libexec/java_home -V
    

    will list the available Java installs and the correct paths.