8

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"

Chef1075
  • 2,176
  • 6
  • 32
  • 46
  • 1
    I am not very sure of what VScode is looking for, but there is no JRE since in Java11. It's just the JDK. – Naman Dec 17 '18 at 15:19
  • 2
    If you're using Maven, have you tried adding `11 11` to your POM? – DodgyCodeException Dec 17 '18 at 16:25
  • @DodgyCodeException I'll try that! Thanks – Chef1075 Dec 17 '18 at 18:32
  • I also have this problem. I am working with legacy code, I have set source and target to 8. and installed the jre/sdk with sdkman.io, what should I configure? – Kuzeko Jan 16 '19 at 11:06
  • @DodgyCodeException it will be great if you add the above comment as an answer and request the seeker to mark that as answer if the response is satisfactory to him/her. In this way the solution to this problem will be searchable as well ! Just a note the referenced comment helped me though. – Siva Senthil Sep 30 '19 at 08:39

3 Answers3

5

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>
Flying Island
  • 51
  • 1
  • 2
0

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"
        }
    ]
    
reb00tz
  • 1
  • 2
-3

I remember there's no jre in jkd 11 any more. Perhaps java can run without jre in java 11. ------I'm a new programer,so that's just my thoughts,maybe false.

  • 1
    not exactly.. https://stackoverflow.com/questions/53111921/how-to-get-java-11-run-time-environment-working-since-there-is-no-more-jre-11-fo – Suraj Rao Mar 04 '19 at 15:15
  • I'm using java11 without jre right now and build some project with vscode.And there is no jre in java11,is there? – user11074381 Apr 19 '19 at 12:27