← Debugging Guides

阅读中文版本

Java — UnsupportedClassVersionError: compiled by a more recent version

Fix UnsupportedClassVersionError by aligning the compiler release target with the runtime JDK.

beginnerdebuggingjavabuild

Symptoms

  • UnsupportedClassVersionError: class file version 61.0, this version only recognizes up to 55.0
  • The app runs locally but fails on the server
  • The error appears after upgrading the build JDK
  • A dependency jar is compiled for a newer Java

Possible causes

  • The code was compiled with a newer JDK than the runtime
  • The build toolchain or release setting targets a higher bytecode level
  • A dependency requires a newer Java than the deployed runtime
  • Different machines use different JDKs for build and run

Diagnosis steps

Read the class file version numbers

App 2>&1 | grep UnsupportedClassVersion

Interpretation

The first number is the compiled class version and the second is the runtime maximum. The gap shows which side to change.

Check the build release target

grep -n "maven.compiler.release\|sourceCompatibility" pom.xml build.gradle

Interpretation

A release target above the runtime JDK produces bytecode the runtime cannot load.

Compare JDKs

java -version ; javac -version ; xcode-select -p

Interpretation

Differing versions between build and runtime explain why it works on one machine and not another.

Root cause

The class files were compiled for a Java version newer than the runtime JDK supports, so the runtime refuses to load them.

Fix

Set the compiler release target to the deployed JDK version, build with that JDK or --release, and upgrade the runtime if a dependency genuinely requires a newer Java.

Verify the fix

Rerun the application and confirm it starts, and confirm the compiled class version matches the runtime maximum.

Symptom walkthrough

Starting the application fails with UnsupportedClassVersionError, and the message gives a class file version and the maximum the runtime recognizes, such as 61.0 versus 55.0. The code was compiled with a newer JDK than the one running it. This often appears after upgrading the build environment while the deployment runtime stayed on an older version.

Fix in practice

Set the compiler release target to match the deployed JDK and build with that target, using –release where applicable so the toolchain produces compatible bytecode. If a dependency truly needs a newer Java, upgrade the runtime rather than forcing an incompatible build.

Verification

Rerun the application and confirm it starts, then confirm the class file version no longer exceeds the runtime maximum. Aligned versions confirm the fix. Documenting the minimum supported JDK keeps build and runtime environments from drifting apart again.

Diagnostic commands

Check the behavior with commands like these:

App 2>&1 | grep UnsupportedClassVersion
grep -n "maven.compiler.release\|sourceCompatibility" pom.xml build.gradle
java -version ; javac -version ; xcode-select -p