CodexBloom - Programming Q&A Platform

Maven build scenarios with 'UnsupportedClassVersionError' after upgrading to JDK 17

👀 Views: 130 💬 Answers: 1 📅 Created: 2025-06-14
maven jdk java-17 build error Java

I've looked through the documentation and I'm still confused about I've been researching this but I'm working with an `UnsupportedClassVersionError` when trying to run my Maven build after upgrading to JDK 17... The behavior message states that a class I compiled with a newer version is being loaded by an older JVM. Here is the relevant part of the stack trace: ``` Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mycompany/MyClass 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 60.0 ``` I've confirmed that my local environment is set to JDK 17 by running `java -version` and `javac -version`, both showing `17`. However, I suspect that the scenario is related to the version of Maven or how it's configured in my project. My `pom.xml` looks something like this: ```xml <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> ``` I initially set the source and target to 1.8 for compatibility reasons, but now that I'm using JDK 17, I want to take full advantage of the new features. I've tried changing those properties to: ```xml <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties> ``` After making that change and running `mvn clean install`, I still get the same `UnsupportedClassVersionError` when running the application. I also checked that my `JAVA_HOME` points to the correct JDK 17 installation. Could there be any other configurations in Maven or dependencies that might be causing this scenario? I’m using Maven 3.8.5 and I’ve ensured all dependencies are compatible with Java 17. Any insights would be greatly appreciated! Is this even possible? What's the best practice here?