Visual Studio Code showing "Java 11 or more recent is required to run. Please download and install a recent JDK"

JavaVisual Studio-Code

Java Problem Overview


Today Visual Studio Code started showing me a pop-up saying:

> Java 11 or more recent is required to run. Please download and install a recent JDK.

I need to use the JDK 8 (working on Apache Beam and that's the last supported version). I have been working on that and haven't had any issues until this came up.

I have read through this article and implemented the points mentioned there.

Here is my workspace settings on Visual Studio Code (I have double-checked the paths)

{
    "java.configuration.updateBuildConfiguration": "disabled",
    "java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home",
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-1.8",
          "path": "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home",
          "default": true
        },
        {
          "name": "JavaSE-11",
          "path": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home",
        }
      ]
}

Other helpful information:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

and

which java
/usr/bin/java

This started happening today even though I have been running JDK 8 on Visual Studio Code successfully for a while now. I don't remember updating Visual Studio Code, so I'm not sure as to why this is being displayed now since apparently the pop-up has been displayed since mid-April (asked on the vscode-java Gitter channel).

Java Solutions


Solution 1 - Java

Change from

"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"

to

"java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"

and keep the rest of the settings as is.

Solution 2 - Java

For future readers. If you are using the extension "Spring Boot Tools" you may get a similar error to this. I had my JAVA_HOME set to java 8 but required java 11 to use the Spring Boot Tools Language Server. It seems that Spring Boot Tools uses whatever your JAVA_HOME environment variable is or in the PATH environment variable, Spring Project Issue. To override your JAVA_HOME variable you'll need to modify the spring-boot.ls.java.home setting.

  1. Open Visual Studio Code
  2. CRTL + , to open the settings
  3. Search spring-boot.ls.java.home
  4. Select 'Edit in settings.json'
  5. Your Java 11 installation → "spring-boot.ls.java.home": "C:\\Program Files\\Java\\jdk-11.0.10"
  6. Save and restart VS Code

Prereq: Have a Java 11 installation

Solution 3 - Java

One workaround is to downgrade the extension "Language Support for Java(TM) by Red Hat" from the most recent version 0.65.0. back to

vscode-java version 0.64.1.

(This is not recommended unless you have restrictions on the JDK version, it is just possible, see the remarks at the bottom. If you can, use the accepted answer of this thread instead.).

Taken from Java 11 or more recent is required to run. Please download and install a recent JDK" #1543, this is how to install the earlier extension version (thanks go to the GitHub user who posted this):

Enter image description here

Please mind:

This should be relevant only for those who cannot install JDK 11 or higher:

  • Due to a 32-bit system (and who by the same time are forced to use an Oracle JDK 8 as their last Oracle version for 32 bit, so that they are not allowed to use the recommended OpenJDK 14 - see JDK Requirements → click at the top at the Java Development Kit link → jump to https://adoptopenjdk.net/)
  • Due to restrictions on a 64-bit system:
    • One plausible reason is that you are not allowed to update Gradle and you have a Gradle version below 4.7, see the github discussion again.
    • One "not that plausible" restriction could be some efficient laziness. You might simply not want to install a new JDK and change the Visual Studio Code settings back to your old JDK only because of a version change of the Java extension :).

You should not do this if you have no important restrictions. The most plausible restriction is that you use Windows 32 bit, which should be relevant only for those who have an old netbook lying around.

In the usual case: upgrade, and then you can still go back to using an older Java version by changing the settings according to JDK Requirements:

> Do I need to migrate my projects to Java 11? > > "NO, you don't! Well, you should, be we're not here to judge. It is > still possible to compile/run Java applications from Java 1.5 to 14, > provided the proper java.configuration.runtimes are configured in the > user's settings.json."

--> This means you can upgrade the extension, install at least Java 11 (JDK 11), and use the Java runtime of your choice <= your installed Java version.

See detailed instructions for Windows 64bit at "Java 11 or more recent is required to run. Please download and install a recent JDK" #1543.

Solution 4 - Java

In Windows,

  1. Download and install JDK 11.

Download and install JDK 11

  1. Once the installation is complete, in C:\Program Files\Java you'll see something like this

C:\Program Files\Java

As you can see, we have JDK 11 in C:/Program Files/Java/jdk-11.0.8.

  1. Open VSC and go to Settings (CTRL + , or Manage icon (bottom left) > Settings) and search for javahome

VSC Settings Java Home

  1. Click in "Edit in settings.json", add C://Program Files//Java//jdk-11.0.8 to java.home and save the file. You should have something like this

Java Home VS Code Settings

{
    "java.home": "C://Program Files//Java//jdk-11.0.8"
}

5. Restart VS Code and you'll see something like this

Security Warning

> Security Warning! Do you allow this workspace to set the java.home > variable? java.home: C://Program Files//Java//jdk-11.0.8

Click allow and you're good to go.


Note: If you get this error and are reliant on Java 8, fbricon mentions,

> you can still compile your projects with Java 8. JDK11 is only > required to run vscode-java.

Solution 5 - Java

About the Java 11 requirement:

The Eclipse platform has decided to require Java 11 as the minimum requirement for its September 2020 release. See Upgrading the Eclipse SDK target environment for the September Eclipse release....

Because vscode-java depends on the Eclipse JDT.LS server, that same requirement to vscode-java. But the timeline is be more aggressive: Indeed, vscode-java usually consumes JDT.LS builds that depend on bleeding edge JDT features, so effectively shipping pre-release versions of Eclipse Platform/JDT. As of July 22nd, 2020, Java 11 is now required for running vscode-java.

This is from:https://github.com/redhat-developer/vscode-java/wiki/JDK-Requirements#java.configuration.runtimes

Solution 6 - Java

I was experiencing the same issue and the following change to my setting.json file resolved the issue. Big thanks to this comment on patch notes.

"java.home": "C:/Program Files/AdoptOpenJDK/jdk-11.0.8.10-hotspot",
"java.configuration.runtimes": [
    {
        "name": "JavaSE-1.8",
        "path": "C:/Program Files/Java/jdk1.8.0_211",
        "default": true
    },
    {
        "name": "JavaSE-11",
        "path": "C:/Program Files/AdoptOpenJDK/jdk-11.0.8.10-hotspot",
    }
]

Solution 7 - Java

  1. Just uninstall all previous JDKs, i.e., less than or equal to JDK 11.

  2. Re-install JDK 11 from https://www.oracle.com/java/technologies/javase-jdk11-downloads.html

  3. Make sure your system variable JAVA_HOME points to the latest installed JDK like "C:\Program Files\Java\jdk-11.0.8" (for Windows)

  4. Restart Visual Studio Code

  5. Go to Workspace settingsJava: Home

  6. Select "Edit in settings.json"

  7. Your settings.json should look like:

    settings.json_image

    {
        "java.completion.favoriteStaticMembers": [
    
            "org.junit.Assert.*",
            "org.junit.Assume.*",
            "org.junit.jupiter.api.Assertions.*",
            "org.junit.jupiter.api.Assumptions.*",
            "org.junit.jupiter.api.DynamicContainer.*",
            "org.junit.jupiter.api.DynamicTest.*",
            "org.mockito.Mockito.*",
            "org.mockito.ArgumentMatchers.*",
            "org.mockito.Answers.*"
        ],
        "java.home": "C://Program Files//Java//jdk-11.0.8"
    }
    

Solution 8 - Java

For people who do not want to install Java 11 and keep using Java 8. You will have to install previous version of extension 'Language Support for Java(TM) by Red Hat redhat.java". The extension version should be 0.64.1 for Java 8.

Please refer the answer in the post below -

https://stackoverflow.com/questions/63043585/visual-studio-code-showing-java-11-or-more-recent-is-required-to-run-please-do/63287737#63287737

Solution 9 - Java

Add this variable in your settings.json file.

"sonarlint.ls.javaHome": "/Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home"

Solution 10 - Java

I have been using Adopt open JDK (Eclipse Temurin) for my Gradle builds and switching to VS Code from Android studio encountered with 'There is no valid JAVA_HOME setting to launch Gradle Language Server. Please check your "java.home" setting.'.

Delving into that issue I found some JDK Installers don't even install Java_Home by default.

Just reinstalling with fields checked, solved the issue. Don't forget to restart VS Code. (no need to edit environment variables at least I didn't have to)

error fixed

hope it helped.

Solution 11 - Java

In 2022 March,

I found the java.home was changed to be recommended to use java.jdt.ls.java.home, then just change it.

And one another setting I did to get rid off that message, re-check the environment variables on your machine, does it set to proper Java 11 or above?

After made those settings, restart VS Code and then go on your work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmcansadoView Question on Stackoverflow
Solution 1 - JavaXavierView Answer on Stackoverflow
Solution 2 - JavaVictor RamosView Answer on Stackoverflow
Solution 3 - Javaquestionto42standswithUkraineView Answer on Stackoverflow
Solution 4 - JavaTiago Martins PeresView Answer on Stackoverflow
Solution 5 - JavaLzx4627View Answer on Stackoverflow
Solution 6 - JavaWarren CloughView Answer on Stackoverflow
Solution 7 - JavaAyush PratapView Answer on Stackoverflow
Solution 8 - Javauser4987870View Answer on Stackoverflow
Solution 9 - JavaManjunath AsundiView Answer on Stackoverflow
Solution 10 - JavaNeailView Answer on Stackoverflow
Solution 11 - JavaNatta WangView Answer on Stackoverflow