skip to Main Content

I am trying to move to visual studio code from my Java work. I have the recommended extensions but I am getting strange errors like:

"The compiler compliance specified is 17 but a JRE 1.8 is used"

I do not have a JDK 17 installed (the project needs to be built with Java 8)

error screen shot

In my root pom.xml I have:

<properties>
    <project.source>1.8</project.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

and in the project .vscode/settings.json:

{
    "java.compile.nullAnalysis.mode": "automatic",
    "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx6G -Xms1G -Xlog:disable",
    "java.configuration.updateBuildConfiguration": "automatic",
    "java.configuration.runtimes": [
        {
            "default": true,
            "name": "JavaSE-1.8",
            "path": "/usr/local/sdkman/candidates/java/current",
        }
    ],
    "java.debug.settings.onBuildFailureProceed": true
}

And to validate this is a Java 8:

~ /usr/local/sdkman/candidates/java/current/bin/java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (Zulu 8.54.0.21-CA-linux64) (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (Zulu 8.54.0.21-CA-linux64) (build 25.292-b10, mixed mode)

On the command line the project builds fine. Any idea what can be causing this?

2

Answers


  1. settings.json

    "maven.terminal.customEnv": [
      {
        "environmentVariable": "JAVA_HOME",
        "value": "/usr/local/sdkman/candidates/java/current"
      }
    ]
    

    Note that ‘maven.compiler.release’ in pom.xml is available only for Java 9 or later.
    https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html

    Toolchain allows you to specify exactly which JDK version to build.
    https://maven.apache.org/guides/mini/guide-using-toolchains.html

    Specify Project Java Version in VSCode
    https://github.com/cypher256/java-extension-pack?tab=readme-ov-file#specify-project-java-version

    Login or Signup to reply.
  2. this could be the Java plugin in vscode configured to Java17, but you are currently using the JRE version of 1.8. You can choose to install the JDK for Java17 on your computer. You can also use Ctrl+Shift+P in vscode to open the command panel. Input Preferences:Open Settings to open and set "java.configuration.compilerArgs":["-source","1.8","-target","1.8"], and then restart vscode to see if that can solve the problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search