Avneet
Avneet

Reputation: 531

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

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

Upvotes: 3

Views: 7622

Answers (2)

Ras
Ras

Reputation: 197

There are two possibilities, the JDK or the .classpath.

Check for JDK.

Since vscode-java 1.2.0, JDK 17 is required.

"Since vscode-java 1.2.0, it publishes platform specific versions to Microsoft VS Code marketplace. The platform versions have JRE 17 embedded in Java extension for platforms such as win32-x64, linux-x64, linux-arm64, darwin-x64, darwin-arm64." Source

Open settings.json. Can open the settings by ctrl+shift+P and type settings.json. Check for the java.jdt.ls.java.home key since java.home is already deprecated. Set the value to your JDK 17 path.

"java.jdt.ls.java.home":"c:\\Program Files\\Eclipse Adoptium\\jdk-17.0.8.7-hotspot",

Don't worry about the java version that you need to use for the project, can set the version by specify java.configuration.runtimes. Like example,

"java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "C:\\Program Files\\Java\\jdk1.8.0_162"
        },
        {
            "name": "JavaSE-1.6",
            "path": "C:\\Program Files\\Java\\jdk1.6.0_45",
            "default": true
        },
        {
            "name": "JavaSE-1.7",
            "path": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.8.7-hotspot"
        }
    ]
Check for .classpath

Open .classpath.

  • Check the container path. Can search for this keyword kind="con".
  • Make sure the name for the last value is same as the value set in java.configuration.runtimes.names.
  • For example I am using JavaSE-1.6, the last value container path should be JavaSE-1.6. So it should be, <classpathentry kind="con"path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclise.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>

Hopefully it helps.

Upvotes: 1

Leandro Arruda
Leandro Arruda

Reputation: 506

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.

Upvotes: 2

Related Questions