Importing java project in visual studio code and getting build path error. unbound classpath container: JRE System library jdk-8.0.202.08

Viewed 2684

My VS Code version-1.55.2 Java path in system->>C:\Program Files\Java\jdk1.8.0_291

I am importing java project in vs code for the first time. Below items already tried:

  1. Java clean server workspace
  2. Checked java log server settings in command pallete and it showing its going to jdk11.
  3. Java Pack extension is already installed.

Attaching image of error, i am getting.

How can i point my code to my jdk 8 location. I used to do same in eclipse IDE in past.enter image description here

I understand that vs code now does not pick jdk 8 and has to be jdk 11.

My settings.json file in vs code as below:

{
    "liveServer.settings.useLocalIp": true,
    "liveServer.settings.CustomBrowser": "chrome",
    "editor.minimap.enabled": false,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "java.home": "C:\\Program Files\\Java\\jdk-11.0.6"
}

and JAVA_HOME is set to same jdk. what else i can try to fix this?

After setting java configuration runtimes below is error i am seeing with my project structure:

enter image description here

Below is my project structure: enter image description here

1 Answers

I did make a simple test, I did choose one of the most popular extensions package for that and did make the settings indicated.

I'm using RedHat Java Extension, but installed with Microsoft Java Extension Pack: https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack, that install RedHat Extension.

In my computer, I had only JDK 8. I'm using linux, I did install JDK simply put in some place, like /usr/lib/jvm, and using update-alternatives to manager the versions, in case I need more than one version.

The documentation of RedHat Extension states that is needed JDK 11 or newer: https://github.com/redhat-developer/vscode-java/wiki/JDK-Requirements#java.configuration.runtimes.

So, I need to download JDK, I choose Oracle Version, but could be OpenJDK, and I nether needed to configue another version, I just put in some place, /usr/lib/jvm, just for organization, and I did define what was needed at VS Code User Settings: Ctrl + Shift + P, to open Pallete, and enter with Preferences: Open Settings (JSON).

"java.home": "/usr/lib/jvm/jdk-11.0.11",
"java.configuration.runtimes": [
    {
        "name": "JavaSE-1.8",
        "path": "/usr/lib/jvm/jdk1.8.0_281",
    }
]

So I have only Java 8, but for the extension needs I did point path to JAVA_HOME, that is "java.home" setting, to JDK 11 Path and setting up the runtime environment with JDK 8.

With this you can try and verify if the bytecode is generated properly with Java defined at "java.configuration.runtimes" setting, that is JDK 8.

Related