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

Created on 11 Oct 2019  路  26Comments  路  Source: redhat-developer/vscode-java

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

Most helpful comment

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

All 26 comments

@piyushkrmaurya could you attach your settings.json?

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

@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

No I did not use flatpak.

@piyushkrmaurya could you send the output of the following command:

ls /usr/share/java/jdk-11.0.4/bin
ls /usr/share/java/jdk-11.0.4/bin

jaotc  jarsigner  javac    javap  jconsole  jdeprscan  jhsdb   jinfo  jlink  jmod  jrunscript  jstack  jstatd   pack200  rmid         serialver
jar    java       javadoc  jcmd   jdb       jdeps      jimage  jjs    jmap   jps   jshell      jstat   keytool  rmic     rmiregistry  unpack200

Is /usr/share/java/jdk-11.0.4/ accessible?

ls -la /usr/share/java/jdk-11.0.4/bin

This path is not pointing to a JDK.

Could you show the entire message?

Same problem

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

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

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

Same issue on Manjaro Juhraya KDE.

openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode)

@Katona's solution worked for me (thank you) :partying_face:

Here's the following for Archlinux (via package manager) :point_down:

  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.

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.

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"

I haven't been able to get this working on a mac yet. AdoptJDK as a pkg file or downloading the tar.gz both don't work. I set the path in VSCode settings and it says it isn't valid.

// for tar.gz
"java.home": "/Users/wbeebe/tools/jdk-11.0.8+10"
// for pkg
"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk'

I don't have two java homes, these are two settings I've tried and neither work.

Screen Shot 2020-09-08 at 11 55 08 AM

I've also tried asdf to install a JDK (which would be preferred) and get the same error as above.

are you using flatpak vscode?

I am not. I'm using VSCode Insiders

Version: 1.49.0-insider
Commit: b6d4fec3714ff897f72c1dab8cc02b7421a8f131
Date: 2020-09-01T05:48:29.841Z (1 wk ago)
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0

I also tried downloading the JDK from here with no luck.

https://jdk.java.net/14/

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 fix the problem with
"java.home": "/usr/lib/jvm/java"

And when you look on /usr/lib/jvm/ you have something similar :

lrwxrwxrwx.  1 root root   26 16 sept. 10:44 java -> /etc/alternatives/java_sdk

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",

It seems that the problem is solved once the devel package is installed (Which makes sense ..)

It seems that the problem is solved once the devel package is installed (Which makes sense ..)

Is this for Linux? I don't see a devel package

Is this for Linux? I don't see a devel package

Hey @benjamindally, look at this link for installation https://docs.fedoraproject.org/en-US/quick-docs/installing-java/#_installing_openjdk_for_development

Don't hesitate if I can help you

Was this page helpful?
0 / 5 - 0 ratings