Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Build path specifies execution environment JavaSE-10. There are no JREs installed in the workspace that are strictly compatible.

I'm having issues with setting up the JREs in my VSCode workspace. I thought the issue was correctly setting up my java.home in my settings.json but I'm still getting this error:

Build path specifies execution environment JavaSE-10. There are no JREs installed in the workspace that are strictly compatible.

I've looked at the answer here (Warning - Build path specifies execution environment J2SE-1.4) but the solution is for Eclipse and not VSCode.

I think it is because the JRE is specifying Java10 and I'm using Java11.

Any suggestions on how to set up the JRE for VSCode?

Also, here is the java version I'm using and my settings.

$ /usr/libexec/java_home -V

Matching Java Virtual Machines (1):
    11.0.1, x86_64: "Java SE 11.0.1"    /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home

And my java.home settings in VSCode:

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

like image 903
Chef1075 Avatar asked Dec 17 '18 15:12

Chef1075


People also ask

How do I fix eclipse build path?

Procedure. In Eclipse select the web project and right-click Build Path > Configure Build Path. This will display the Java Build Path window. Add the CICS and Liberty libraries, click Add Library > CICS Liberty libraries > Next > Finish.


2 Answers

To totally remove the warnings/errors, I believe you need to:

  • ensure that JDK 10 is installed
  • as per limitations, use "JavaSE-10" as the name in the java.configuration.runtimes array in your settings.json

Given the question was posed in 2018, for my current version of VS Code (1.49.2), it will use a higher JDK version in "compatibility" mode and similar messages are just warnings.

As I had some difficulty myself figuring out and configuring everything, and this still ranks high on Google searches, I am documenting the full instructions for setting the java.configuration.runtimes (particularly in regards to Windows and WSL), since it is preferable for me to not change the entire default JDK using the java.home setting (particularly since this might break JSL also if using JDK versions < 11, as explained below).

According to:

  • https://code.visualstudio.com/docs/java/java-project#_configure-jdk:

    • the Java Language Server requires Java SE 11 or later
  • https://github.com/redhat-developer/vscode-java#setting-the-jdk

    • the java.home setting should be used to point to the JDK used by the JLS, and also code compilation if not explicitly overridden
    • there is a precedence for the variables referenced, i.e.:
      • the java.home setting in VS Code settings (workspace then user settings)
      • the JDK_HOME environment variable
      • the JAVA_HOME environment variable
      • on the current system path
    • to compile against a different JDK, set the java.configuration.runtimes in the respective settings.json (i.e. workspace and/or user):
      "java.configuration.runtimes": [
        {
          "name": "JavaSE-1.8",
          "path": "/path/to/jdk-8",
        },
        {
          "name": "JavaSE-11",
          "path": "/path/to/jdk-11",
        },
        {
          "name": "JavaSE-14",
          "path": "/path/to/jdk-14",
          "default": true
        },
        {
          "name": "JavaSE-15",
          "path": "/path/to/jdk-15",
          "default": true
        },
      ]
      
    • NOTE: I am unsure why the example has two defaults, but the example from their own Wiki and the VS marketplace description have only one.

To edit the settings.json to add (or edit) the java.configuration.runtimes setting/s:

  1. press CTRL+, (comma)
  2. choose the correct "heading"/settings.json you are attempting to edit (i.e. user or specific workspace/s) (screenshot showing 3 environments)
  3. type "java.configuration.runtimes" in the search box
  4. if "No Settings Found" is returned, edit the settings.json file directly by clicking on the `Open Settings (JSON)' button near the top right of the window (as per above screenshot)
  5. edit the appropriate settings.json and enter your customised java.configuration.runtimes snippet (as exemplified above), ensuring to use only the allowed "name"s (as mentioned above) and using the correct paths (taking into account if it is Windows or Linux paths - the latter applicable to WSL)
  6. close the settings.json edit window
  7. set your Maven pom.xml's maven.compiler.source and maven.compiler.target, synchronising the project's Java classpath and configuration when prompted (which will also update your Eclipse org.eclipse.jdt.core.prefs' org.eclipse.jdt.core.compiler.codegen.targetPlatform, org.eclipse.jdt.core.compiler.compliance and org.eclipse.jdt.core.compiler.source accordingly (if it also exists)

Example java.configuration.runtimes snippet from settings.json:

  • Windows (JDK 1.8 and 12 installed)

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "C:\\Program Files\\Java\\jdk1.8.0_261"
        },
        {
            "name": "JavaSE-12",
            "path": "C:\\Program Files\\Java\\jdk-12.0.1"
        }
    ]
    
  • WSL (remote) (JDK 1.8 and 11 installed):

    "java.configuration.runtimes": [
        {
            "name:": "JavaSE-1.11",
            "path": "/usr/lib/jvm/java-11-openjdk-amd64"
        },
        {
            "name": "JavaSE-1.8",
            "path": "/usr/lib/jvm/java-8-openjdk-amd64"
        }
    ]
    
like image 125
reb00tz Avatar answered Oct 04 '22 08:10

reb00tz


In my case, I have setup Maven as the build environment for Java within VSCode. For maven, I found that one of the build properties in pom.xml was set to Java version 1.8, which was older than what I was using, namely 1.11. Once I updated the property as below, the warning disappeared.

<properties>
        <java.version>1.11</java.version>
</properties>
like image 37
Flying Island Avatar answered Oct 04 '22 08:10

Flying Island