microsoft / vscode-java-debug

Java Debugger for Visual Studio Code.
Other
530 stars 339 forks source link

Wrong Java runtime used JRE 11 vs. JRE 17 #1406

Open ole1986 opened 1 year ago

ole1986 commented 1 year ago

Wrong Java runtime used

Environment
Steps To Reproduce
  1. Trying to debug spring boot

No special launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch Application",
            "request": "launch",
            "mainClass": "de.xxx.xxx.Application",
            "projectName": "xxx-application",
            "env": {
                "SPRING_PROFILES_ACTIVE": "debug",
            },
            "vmArgs": "-Xms128m -Xmx128m"
        }
    ]
}

Java Configure Runtime for Projects outputs wrong java version

image

Should be 17 (works on other enviroments - E.g. eclipse)

Current Result
Error: Unable to initialize main class de.ewe.gisatfuture.servicehub.Application
Caused by: java.lang.UnsupportedClassVersionError: org/springframework/web/servlet/config/annotation/WebMvcConfigurer has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Expected Result

Debugger should simply run

Additional Informations

Workaround: mvn spring-boot:run does work

testforstephen commented 1 year ago

Could you pls share a sample project to reproduce the issue?

ole1986 commented 1 year ago

Must have something to do with multi module projects, since the parent one does not seem to recognize the java version as shown in the screenshot

<properties>
    <java.version>17</java.version>
    [...]
</properties>

I assume it is not necessary to include the java.version property in every child module using <parent>(...)</parent> declaration in its child.

Another workaround is exactly this, adding <java.version>17</java.version> to all child modules which is IMO a bad idea

ole1986 commented 1 year ago

All projects i am working with are now affected and can no longer be debugged with this extension

testforstephen commented 1 year ago

I tried with https://github.com/spring-guides/gs-multi-module/tree/main/initial, where I moved "java.version" property from child pom.xml to parent pom.xml, it still worked. All child modules were recognized as version 17. Could you share a sample project in github for us to reproduce it?

ole1986 commented 1 year ago

Unfortunately a cannot quickly provide you an example project. Another workaround is to configure java.configuration.runtimes as follow

"java.configuration.runtimes": [
        {
            "name": "JavaSE-17",
            "path": "/usr/lib/jvm/java-17-amazon-corretto",
            "default": true
        }
   ],

After this I could still see in the footer that the wrong path is being used (my old /usr/lib/jvm/openjdk-11-(...)) image

So I completely removed the old openjdk JVM. Finally debugging worked again. BUT STILL JavaSE-11 is visualized with the "new" amazon-coretto-17 image

How do I fix the "Language Level" property?

BTW Even after the java-jdk-17 is being pulled, still shows Java 11 in the "Runtime for Projects" while every parent *.pom has java.version 17 defined

image
testforstephen commented 1 year ago

The Java language server reads the language level from your pom.xml. It appears that there is an issue when importing your Maven projects, but it is difficult to determine the root cause from just a few screenshots.

ole1986 commented 1 year ago

I can provide you with the pom.xml contents

Frontend module: (mostly javascript) Backend Module: (java part)

Downloads.zip