vscode-java: Openjdk is being treated as invalid JDK on vscode for linux

Issue Type: Bug

The following error is received on Configure Java Runtime Extension Page of the Language Support for Java Extension:

This path is not pointing to a JDK.

But java commands are working alright in the terminal.

echo $JAVA_HOME gives /usr/share/java/jdk-11.0.4 and java --version produces this output:

openjdk 11.0.4 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu219.04) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu219.04, mixed mode, sharing)

Extension version: 0.50.0 VS Code version: Code 1.39.1 OS version: Linux x64 5.0.0-31-generic snap

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 21
  • Comments: 29 (3 by maintainers)

Most upvoted comments

Hi @tarun0,

I had a similar issue on Ubuntu 19.10. Installing openjdk-11-jdk explicitly fixed it. The directory /usr/lib/jvm/java-11-openjdk-amd64/ contained a jre before installing the jdk.

Gabor

Same issue. OS: Ubuntu 18.04.3 LTS

ls -la /usr/lib/jvm/java-11-openjdk-amd64 gives following output (after changing the owner to tarun from root but even that didn’t solve)

drwxr-xr-x 7 tarun root 4096 Dec 16 15:06 . drwxr-xr-x 3 root root 4096 Dec 16 15:06 … drwxr-xr-x 2 tarun root 4096 Dec 16 15:06 bin drwxr-xr-x 4 tarun root 4096 Dec 12 15:11 conf lrwxrwxrwx 1 tarun root 42 Jul 18 23:51 docs -> …/…/…/share/doc/openjdk-11-jre-headless drwxr-xr-x 72 tarun root 4096 Dec 12 15:11 legal drwxr-xr-x 6 tarun root 4096 Dec 16 15:06 lib drwxr-xr-x 4 tarun root 4096 Dec 12 15:11 man -rw-r–r-- 1 tarun root 1161 Jul 18 23:51 release

Below is the complete error (doesn’t point to jdk) Screenshot from 2019-12-17 11-14-35

On Fedora 32, I finally got it working by installing java-11-openjdk java-11-openjdk-devel and setting this configuration in vscode:

"java.home": "/usr/lib/jvm/jre-11-openjdk",

WOOOOOOOOOOOO!

Found the answer here.

https://github.com/redhat-developer/vscode-java/issues/108

For OSX, use:

"java.home": "/Users/wbeebe/tools/jdk-14.0.2.jdk/Contents/Home/",

I fixed it by installing openjdk-11-jdk-devel package.

On archlinux and manjaro, /usr/lib/jvm/default is symlinked to the default JDK version. However, the extension doesn’t seem to recognize/follow the symlink, and you have to explicitly point it to a specific version /usr/lib/jvm/java-14-openjdk.

@Katona’s solution worked for me (thank you) 🥳

Here’s the following for Archlinux (via package manager) 👇

  1. Install jdk: $ pacman -S jdk-openjdk (or whichever version you wish)
  2. Add path to VS Code’s settings (settings.json):
{
    ...
    "java.home": "/usr/lib/jvm/java-13-openjdk/",
    ...
}

note: before installing jdk, as mentioned above, I installed jre with $ pacman -S jre-openjdk. Also, my jdk path contains 13 as it is the version I installed… you might want to use the ls command on your jvm folder and check your jdk path: $ ls /usr/lib/jvm.

Here is my settings.json { “java.configuration.updateBuildConfiguration”: “interactive”, “java.home”: “/usr/share/java/jdk-11.0.4”, “java.completion.enabled”: true }

For anyone working in the updated vscode where the new setting is java.jdt.ls.java.home instead of java.home, I managed to solve the issue by realizing there are two locations where it defines java home (user and workspace) and they were set to different things. I changed them to the same path and it seems to have worked.

I solved it by Downloading AdoptJDK and specifying the path of the downloading JDK in java.home in settings.

"java.home": "/home/ritam/Tools/jdk-14.0.2+12"

@piyushkrmaurya did you install vscode via flatpak? If that’s the case then you should look into https://github.com/redhat-developer/vscode-java/issues/510#issuecomment-462567417