10

I saw this,

Java runtime could not be located

and clicked on it. It redirected me to the Red Hat site and made me download Red Hat Developer Studio, but as I said, I want it in Visual Studio Code. I did download the JDK, but what should I do next?

3

2 Answers 2

21
  • Press Ctrl+comma.
  • Search for "java.home".

In case you are on the newest Visual Studio Code version:

Type in your Java path (don't forget to put the path in " ").

In case you are on an older version of Visual Studio Code:

  • Click on the pencil next to the line starting with "java.home".
  • click on "Copy to settings".
  • Type in your Java path (don't forget to put the path in " ").
  • Press Ctrl + S.

If you don't know your Java path, type in which java in your terminal (on Windows, please note the right format, e.g., "java.home": "C:/Program Files/Java/jdk-11.0.2").

5
  • hi, amirali followed step 1,2 and 3 without problems, but clicking ctrl+'s' nothing happens how do I finalize the changes in the workspace settings? Jan 23, 2019 at 8:00
  • @FrancescoIapicca What's your operating system? Have you used vscode before? And please share what where java returns with us.
    – amirali
    Jan 23, 2019 at 8:52
  • 1
    I'm on win10, I use vscode for dart and flutter, but I have to import an .aar file and call the service using java(hopefully kotlin), so yes (I use it) and no (never with java) [edit: {"java.home":"C:\\Program Files\\Java\\jdk-11.0.2" } Jan 23, 2019 at 8:55
  • 2
    @FrancescoIapicca Have you added "java.home": "C:/Program Files/Java/jdk-11.0.2" to your settings.json file? please make sure you have written it in correct format.
    – amirali
    Jan 23, 2019 at 9:01
  • 4
    java.home is deprecated now. use java.jdt.ls.java.home Feb 11, 2022 at 4:02
3

Shifting to Java 11 did the trick for me. That is the minimum version required to run the Language Support for Java extension. After installation, open your settings.json file with the following:

  • Ctrl or CMD + Shift + P
  • Type "settings"
  • Click on "Preferences: Open Settings (JSON)"

Then add this line:

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

Don't forget a trailing comma if you add this setting before another.

1
  • 1
    The java.home variable defined in Visual Studio Code settings (/usr/lib/jvm/java-11-openjdk-amd64) does not point to a JDK. May 27, 2021 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.