javaspring-bootmaven

Generate for JRE 11 from JDK 17


I have a Spring Boot project, my DEV is OpenJDK 17.

My target platform is Java 11.

When running my DEV generated app on my target I get this:

Fehler: Beim Laden der Klasse org.springframework.boot.loader.launch.JarLauncher ist ein LinkageError aufgetreten
java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/launch/JarLauncher 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

Well ok - that makes sense.

But then I added this to my pom.xml and the problem does not disappear:

<properties>
    <java.version>11</java.version>
    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.release>11</maven.compiler.release>
</properties>

How can I generate code for my target?


Solution

  • How can I generate code for my target?

    You are already doing it. You've told Maven to generate class files that Java 11 can run, and so it has.

    But you still get an error - that Java 11 JVM is loading your code (which it is doing just fine), but... it also loads all your dependencies, which includes Spring Boot 3, and that's not something it can do, as Spring Boot 3's classes are compiled for Java 17 and up.

    That's because Spring Boot 3 is defined as requiring Java 17.

    Spring Boot 3, just like other dependencies, is not compiled by your Maven process. They are compiled by the Spring team and your Maven simply downloads them for you. It doesn't recompile them. It has no facilities to do such a thing.

    That's why the error you get is referring to org.springframework.boot.loader.launch.JarLauncher, and not one of your own classes.

    You might then ask:

    Okay, how do I tell Maven to downgrade Spring Boot 3's classes to Java 11?

    You can't do that. You must either downgrade your Spring Boot version to 2.X.X, or upgrade your target Java to 17 or up.