redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

JDT-LS doesn't detect Java 19 installation in standard location #3043

Open mickaelistria opened 1 year ago

mickaelistria commented 1 year ago

On my machine, I have Java 19 installed in a standard location. Both CLI or Eclipse IDE do find it properly apparently. When trying to open a project defined in Eclipse IDE and that requires Java 19 (working fine in Eclipse IDE), vscode-java throws tons of errors with no assistance/quickfix to remediate those.

Environment
Steps To Reproduce
  1. On my Fedora, Java 19 is installed with usual dnf install java-openjdk-latest
  2. Generate a dummy project in Eclipse IDE targeting Java 19; play with it a bit to verify Eclipse IDE can deal with it
  3. Import the project in VSCode with Java extension

testProject.zip

Current Result

Unbound classpath container: 'JRE System Library [JavaSE-19]' in project 'sandboxJava' message and tons of unresolved types from the JRE

Expected Result

Everything fine

Additional Informations

I would expect JDT-LS to detect Java 19 from such a standard directory; and also to provide an helpful quickfix about remediation (even just linking to documentation would be better)

fbricon commented 1 year ago

where is java-openjdk-latest installed? Do you know how does Eclipse find it automatically?

mickaelistria commented 1 year ago

where is java-openjdk-latest installed?

/usr/lib/jvm/...

Do you know how does Eclipse find it automatically?

I tried a fresh workspace and it doesn't seem to find it automatically. I imagine I had it configured a while ago and the symlink magic does the trick to detect version change. I will open an issue to JDT Core about looking up Java installation from usual folders.

mickaelistria commented 1 year ago

I've opened https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/230 for JDT, I think it's the best place to host the fix. In the meantime, it would still be convenient if JDT-LS offered a quick-fix to assist users in binding the JRE to an installation.

mickaelistria commented 1 year ago

And a PR for JDT debug (core and UI) https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/230 . When this is merged, then my case of standard Java 19 not being detected should be automatically resolved.

koppor commented 1 year ago

I think, this can happen if an unsupported JDK version is used. As of today, this is JDK 20.

I am using devcontainer's java feature, which uses SDK man to install the JDK. That puts the JDK in /usr/local/sdkman/candidates/java/current (and sets JAVA_HOME correctly). When putting that path as java.jdt.ls.java.home, the import by the normal Java extension works. When executing the debugger, that one fails with

Unbound classpath container: 'JRE System Library [JavaSE-20]'

I did not find any hint to configure the JDK at https://code.visualstudio.com/docs/java/java-debugging.

It turns out that I needed to go back to JDK 19.

Adding following to .vsdoce/settings.json was not necessary:

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-19",
            "path": "/usr/local/sdkman/candidates/java/current"
        }
    ]