You upgraded the build to JDK 17, deployed the jar, and the service died with UnsupportedClassVersionError ... (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0. The error is a version handshake, not a corrupted build: one Java installation compiled the class, and a different one tried to load it. This guide decodes both numbers, shows how to find the JVM that actually launched your code in a shell, build, IDE, container, or systemd unit, and then picks a fix that will not break on the next deployment.
Table of Contents
- Decode the Two Numbers in the Error
- Check Which Bytecode and Runtime You Have
- Follow the Runtime That Actually Failed
- Choose the Right Fix
- Prevent the Next Outage
- Conclusion
Decode the Two Numbers in the Error
The message contains two class file versions. In the example above, 61.0 is the version of the class being loaded, and 55.0 is the highest version the running JVM accepts. The class file format stores a major_version and a minor_version, and the JVM specification's class file version rules state that a conforming JVM supports only the class file versions up to its own release. A Java 11 JVM understands class files up to 55, so it cannot load a 61 class, even if the source code is otherwise compatible.
From Java 5 onward, subtract 44 from the major version to get the Java feature release. For version 61:
61 - 44 = 17
The ClassFile API constants for Java 17, 21, and 25 confirm the mapping for recent LTS releases: Java 17 is 61, Java 21 is 65, and Java 25 is 69.
| Class file version | Java release | Notes |
|---|---|---|
| 52.0 | Java 8 | LTS |
| 55.0 | Java 11 | LTS |
| 61.0 | Java 17 | LTS |
| 65.0 | Java 21 | LTS |
| 69.0 | Java 25 | LTS |
The number identifies the target release, not the compiler build. A JDK 21 compiler running with --release 17 also writes 61.0, so use the build configuration to find the compiler rather than relying on the class version alone.
The minor version is usually 0. For class file versions 56 and above, a minor version of 65535 marks a class compiled with preview features, so 61.65535 also requires --enable-preview on the runtime. That is not the usual cause of a deployment failure, but it explains an unfamiliar second number.
Check Which Bytecode and Runtime You Have
Start with the artifact that failed, not with the JDK on your laptop. The stack trace names the class that could not be loaded; use that class name.
javap -verbose -classpath build/classes/java/main com.example.Main | grep 'major version'
java -version
javac -version
printf '%s\n' "${JAVA_HOME:-<unset>}"
mvn -version
gradle -version
The javap -verbose option prints additional class file information, including the major version. A result of major version: 61 confirms the class needs Java 17 or newer. If Maven built the project, the class directory is usually target/classes. If the project has a wrapper, ./mvnw -version and ./gradlew -version show the JVMs the build itself will use. On Windows, use Select-String in place of grep and echo %JAVA_HOME% for the environment check.
If the class is inside a plain jar, point javap at the jar:
javap -verbose -classpath app.jar com.example.Main | grep 'major version'
For a Spring Boot executable jar, application classes live under BOOT-INF/classes, so extract one first:
unzip -p app.jar BOOT-INF/classes/com/example/Main.class > /tmp/Main.class
javap -verbose /tmp/Main.class | grep 'major version'
Then compare with the runtime. java -version reports the JVM the shell will launch. javac -version reports the compiler on PATH, which may be a different installation and may not be the compiler a toolchain-driven build used. JAVA_HOME is a convention used by Maven, Gradle, and some launchers; it is not guaranteed to match PATH. Print it explicitly, and on Linux locate the real binary with command -v java and readlink -f "$(command -v java)".
Two disagreements are common: PATH points at Java 17 while JAVA_HOME points at Java 11, or JAVA_HOME points at 17 while a systemd unit or container runs an older java. If the machine does not actually have JDK 17 installed, or JAVA_HOME is empty or stale, fix that first by following the step-by-step JDK 17 installation and JAVA_HOME guide; changing compiler flags will not help a runtime that is not there.
On macOS, /usr/libexec/java_home -V lists the installed JDKs. On Windows, where java and echo %JAVA_HOME% show the equivalent.
Follow the Runtime That Actually Failed
The failing process may not be the one in your terminal. Work through the four places where a Java runtime is chosen.
The Shell and javac
When you run java or javac, the shell resolves the first matching executable on PATH. A version manager such as SDKMAN or jabba can add shims, and a second JDK installed later can move the order. java -version answers the runtime question; javac -version answers the compiler question. They can legitimately differ.
If the error comes from a hand-run java -jar, check the shell that ran it. A CI step, a cron job, or a colleague's SSH session may have a different PATH.
Maven and Gradle Builds
Maven starts on the JVM selected by JAVA_HOME or by the mvn launcher, then the compiler plugin compiles with that JVM unless a toolchain overrides it. mvn -version prints the Java version Maven itself is using. Setting maven.compiler.release changes the bytecode target, not the JVM that runs Maven or the tests. Maven toolchains let you build with a JDK that differs from the one running Maven, which is useful when CI has one JDK and the project needs another.
Gradle has a launcher JVM and a daemon JVM. Recent Gradle versions print both in gradle -version. JAVA_HOME, org.gradle.java.home, and the IDE's Gradle JVM setting can each influence which one starts. A Java toolchain selects the JDK used to compile and run tests. Gradle's toolchain documentation warns that sourceCompatibility and targetCompatibility only tell the compiler what bytecode to produce and do not choose the JDK. A daemon on an unexpected JDK can change compile and test behavior even when the launcher looks correct.
IDE Run Configurations
An IDE adds another layer. The project SDK controls code insight and often compilation, but an Application run configuration has its own JRE field. A Gradle project also has a Gradle JVM setting separate from the project SDK and the toolchain. After a JDK upgrade, a run configuration created months ago can still point at Java 11 while the command-line build uses 17. Check the run configuration's JRE and the Gradle JVM, not just the project structure dialog.
Containers and systemd
A container carries its own JDK, so the host's java is irrelevant. Run docker run --rm --entrypoint java your-image -version to see the runtime inside the image without going through the application entrypoint. In a multi-stage Dockerfile, the builder may use eclipse-temurin:17-jdk while the final stage still uses an older 11-jre tag; the final stage is the one that fails. The Adoptium container image documentation describes the <java-version>-<image-type>-<os-version> tag scheme, so eclipse-temurin:17-jre is a Java 17 runtime. For Kubernetes, inspect the image tag in the Deployment and run kubectl exec <pod> -- java -version if the image includes a java binary.
systemd starts the command in ExecStart directly, with an absolute path, and does not read your shell's .bashrc or .zshrc. Exporting JAVA_HOME in an interactive session will not affect the unit. Run systemctl show -p ExecStart -p Environment myapp.service to see the binary and environment the unit actually uses. If ExecStart points at /usr/bin/java from Java 11, changing only Environment=JAVA_HOME will not change that absolute path. Update the path to the JDK 17 binary or change the alternatives symlink deliberately, then run systemctl daemon-reload and restart the service.
Choose the Right Fix
The version pair tells you which side to change. Use the cheapest fix that matches the runtime you are allowed to run.
| What you see | What it means | First fix |
|---|---|---|
61.0 vs 55.0
|
Java 17 class on a Java 11 runtime | Run on 17+, or compile with --release 11
|
65.0 vs 61.0
|
Java 21 class on a Java 17 runtime | Run on 21+, or replace the 21-only dependency |
| Your classes are 61, one dependency is 65 | Mixed bytecode in one classpath | Raise the runtime or downgrade/replace the dependency |
Unsupported class file major version 61 in Gradle, Spring, or JaCoCo |
The tool's bytecode parser is older than 17 | Upgrade the tool |
Raise the Runtime
If the application and its dependencies really need Java 17, give them Java 17. For a container, change the runtime stage's base tag to a Java 17 JRE and redeploy. For systemd, update ExecStart and Environment in the unit. For CI, update the job image or setup-java version. After the change, run java -version inside the same environment that runs the app; checking it on your laptop is not enough.
Do not raise only the compile JDK. If the build already produced 61, the compile side is fine; the failure is on the runtime side.
Compile for the Oldest Supported Release
If the production runtime must stay on Java 11, compile for 11. javac --release 11 compiles against the Java 11 API and emits 55.0 class files. Oracle's javac reference for --release explains that it applies the language rules and API of the specified release and cannot be combined with -source or -target. On JDK 17, the supported --release values are the current release and a limited set of earlier ones; javac --help lists them.
javac --release 11 -d out @sources.txt
Here sources.txt is a list of source files, or you can use your build tool.
For Maven, set the release property:
<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>
You can also use <release>11</release> in the compiler plugin. The Maven guide to targeting a Java version recommends release because it catches APIs that do not exist in the older release, and warns that target alone does not guarantee the code will run on that JRE.
For Gradle, set the release option on compile tasks:
tasks.withType<JavaCompile>().configureEach {
options.release = 11
}
Use the oldest release your production runtime supports, not the newest one your build JDK understands.
Caveat: if the code uses Java 17 APIs or language features, --release 11 will fail. That is useful feedback: either the runtime must be 17+, or the code must change. Recompiling is not a substitute for a runtime upgrade when the application genuinely depends on newer APIs.
Replace a Dependency Built for a Newer Release
If your own classes are 61 and the runtime is 17, but the stack trace points at a library class with 65, the dependency is the problem. Confirm with javap, then find the artifact with mvn dependency:tree or Gradle's dependencyInsight. Upgrade, downgrade, or exclude the library; if it only ships Java 21 bytecode and you need it, the runtime must be 21 or newer. Recompiling your source cannot lower someone else's class files.
Spring Boot fat jars can hide this: the failing class may live in a nested jar under BOOT-INF/lib, not in your code. Extract the nested jar and run javap against the class named in the stack trace.
Prevent the Next Outage
Make the build target and the deployment runtime explicit, and fail early when they drift.
-
Pin the build JDK. Use Maven toolchains or a Gradle toolchain so local builds, CI, and release jobs compile with the same JDK.
JAVA_HOMEalone is too easy to override. -
Use
release. Setmaven.compiler.releaseoroptions.releaseto the oldest supported Java. This keeps bytecode at 55 or 61 intentionally and stops code from compiling against APIs that the deployment runtime lacks. -
Enforce dependency bytecode. The extra-enforcer-rules
enforceBytecodeVersionrule checks dependencies transitively and fails when any class exceeds the configured maximum. ConfiguremaxJdkVersionto 17, ormaxJavaMajorVersionNumberto 61, and run it in thevalidatephase so a library built for Java 21 cannot silently enter a Java 17 deployment. -
Test the artifact on the production runtime. In CI, run the built jar or image with the same base image and tag used in production, then execute a smoke test.
java -versionplus one startup assertion catches a wrong runtime before release. If production uses systemd, run the unit'sExecStartcommand in staging with the same binary path. -
Keep tags explicit. Prefer
eclipse-temurin:17-jreover a floating tag. A moving tag can change the runtime under a service without a code change. - Check test JVMs too. Surefire, Failsafe, and Gradle test tasks can use a different JVM from the main compile. If only tests fail, check the test task's JDK separately.
Conclusion
Class file version 61 means Java 17 bytecode. UnsupportedClassVersionError says a JVM older than that loaded the class, so the resolution is either a Java 17+ runtime or a lower compile target. Decode both numbers, locate the JVM that actually launched the process (shell, Maven or Gradle, IDE, container, systemd), and change the side that is wrong. Pin toolchains, compile with release, and enforce a maximum dependency bytecode version so the next JDK upgrade does not turn into another production outage.
Top comments (0)