Home > OS >  Visual Studio Code will not recognize any JDKs
Visual Studio Code will not recognize any JDKs

Time:08-31

I am fairly new at this so please be patient as I will not always know what you are talking about and may not know what information is helpful to provide. I am trying to set up VSCode as my IDE for java on my macOS Monterey 12.3.1 device. I have the Java Extension Pack that Microsoft recommends.

Anytime I open a .java file, I get an error notification saying "The java.jdt.ls.java.home variable defined in Visual Studio Code settings does not point to a JDK. Source: Language Support for Java by Red Hat."

The variable it is talking about, I copied the path directly from the jdk folder that is returned when I run "java -version" through the terminal. Any other jdk version I have tried, it also does not recognize. Even when I go through VSCode and click "locate an existing jdk" and point it to the location, it tells me the folder I've selected is not a jdk.

I have deleted and reinstalled all of my jdks as well as VSC several times. I even tried downloading the package of VSC, a JDK, and the java extensions that Microsoft put together. I do not know what else to do.

I have seen some online forums talking about the environment variable JAVA_HOME, but I am having trouble grasping the concept or understanding what I can do with that information.

Please let me know if you have any suggestions or if you need me to provide more information. Thank you!

CodePudding user response:

Follow this enter image description here

If you need to specify the JDK, you can use the following configuration in the settings.json

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.332.9-hotspot",
            "default" : true,
        },
        {
            "name": "JavaSE-17",
            "path": "C:\\Users\\Admin\\AppData\\Local\\Programs\\Eclipse Adoptium\\jdk-17.0.3.7-hotspot",
        },
    ],

It can also be selected in the JAVA PROJECTS panel

enter image description here

You can also use java.jdt.ls.java.home to specify the folder path to the JDK (17 or more recent) used to launch the Java Language Server.

    "java.jdt.ls.java.home": "c:\\Users\\Admin\\AppData\\Local\\Programs\\Eclipse Adoptium\\jdk-17.0.3.7-hotspot",

The above paths are the folders where Java is installed, not Java.exe.

About JAVA_HOME

This is an environment variable set for your system so that Java commands are available anywhere on your machine.

Take windows as an example (sorry I don't have a mac)

  • Add JAVA_HOME to system environment variables

    enter image description here

  • Then add the java path to path

    enter image description here

The effect is equivalent to adding the Java bin path directly to the Path

  • Related