vscode-java: JAVA_HOME is not pointing to a JDK.

[provide a description of the issue]

Environment
  • Operating System: macOS Mojave

  • JDK version: OpenJDK 11.4

  • Visual Studio Code version: 1.38.1

  • Java extension version: 0.48.0

Steps To Reproduce
  1. Opening Java Project
Current Result

After opening a Java project, the configure window pops up and shows, that the JAVA_HOME is set, but it’s not pointing to a JDK. Bildschirmfoto 2019-09-16 um 14 41 50

The JAVA_HOME path is correctly set.

Expected Result

JDK should be found.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 30 (7 by maintainers)

Most upvoted comments

I had the same problem on my Mint. The problem was fixed after I reinstalled openjdk-11. I used the following command. Should work for Ubuntu as well. sudo apt install openjdk-11-*

Got the same error on Linux Debian 10.5 (buster). I realized that if I was launching VSC by the application itself, it was doing this error, while if I launch VSC through the terminal, all’s good. Maybe user’s settings.

Let me help to form a guide from most of above cases.

Root cause

Because of the confusing name of packages, some Linux users actually installed a JRE (Java Runtime Environment) instead of a JDK (Java Development Kit). As ./bin/javac doesn’t exists under path of Java home folder, the extension recognizes it as a JRE instead of a JDK (which is required), thus prints this error message.

Follow below steps to fix it

  • Open command palette, run “Java: Configure Java Runtime”, to find out which java homedir is taking effect.
  • Check if .bin/javac exists under above path.
    • If yes, report to us with detailed information.
      • installed java packages on your Linux distribution
      • recognized java home directory
      • file permission of the related files
      • etc…
    • If no (most of the cases), try installing a JDK instead of JRE. E.g many packages have confusing names, make sure you installed the correct one
      • on Debian/Ubuntu, install openjdk-11-jdk with an additional jdk appended
      • others may append devel, src, all etc.

Getting same error on Linux openSUSE,

The JAVA_HOME environment variable (/usr/lib64/jvm/java-11-openjdk-11) does not point to a JDK.

JAVA_HOME set correctly:

export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk-11

jdk

[UPDATE]: It seems what I had install was only the JRE even though it’s named openjdk?

I ended up downloading the package suggested to me by vscode in the, “Configure Java Runtime” setting, point JAVA_HOME to it and everything works, no errors.

You can also down the jdk from here: https://jdk.java.net/

Update A better solution might be to use SDKMAN to install java, jdk and sdk! https://sdkman.io/

I have same issue on Fedora 32. I have set all paths as required but still issues

Not sure why this coninues to be an issue for me. I enjoy using VSC for quick edits where VI* isn’t the only option available. Although with my $JAVA_HOME set, exported automatically, and picked up on automatically by other IDEs such as IntelliJ, Eclipse, AND NetBeans… VSC even shows the path it found, but instead decides to mention that in my settings “$JAVA_HOME” is an invalid path…? wuh wuh?

Advice for a JDK8 user?

@phhoef I guess you did set the wrong JAVA_HOME, by appending an extra whitespace.

From the bottom-left error box in your screenshot, you can see there is a whitespace before ), and check the source code, it must be from your JAVA_HOME.

Back to compare the original screenshots, you can see more clear that your JAVA_HOME was longer than mine, with an extra whitespace. image image

try "java.home": "/home/agilob/.sdkman/candidates/java/14.0.1.hs-adpt" there’s no 14.0.1-open in your candidates directory.

FYI, I’ve just tried the latest AdoptOpenJDK 11, and it works well for me. Screen Shot 2019-09-17 at 11 03 32 AM

A JDK(instead of JRE) is required. Please check

  • if bin/javac exists under JAVA_HOME? e.g. using command ls $JAVA_HOME/bin/javac.