java.lang.UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 65.0): how to fix it
java.lang.UnsupportedClassVersionError: ... has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0 means the class was compiled for Java 21 and is being run on Java 17. Run it on a Java at least as new as the one it was built for, or compile for the older release with --release, Maven's maven.compiler.release or a Gradle toolchain.
By Livops team, the people who build and run LivopsUpdated
As the java launcher prints it when the class it starts was compiled for Java 21 and the runtime is Java 17[3][6] (com.example.App stands for your main class):
$ java -jar app.jar
Error: LinkageError occurred while loading main class com.example.App
java.lang.UnsupportedClassVersionError: com/example/App has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
When the class is loaded later rather than as the main class, the same java.lang.UnsupportedClassVersionError line opens a stack trace instead.
This page explains what the two numbers mean, which Java release each one is, and the two fixes: run on a Java as new as the build, or build for the older Java. The last section shows where it surfaces on Livops.
What does the error mean?
Every .class file records the version of the class file format it was written in, a major and a minor number[1]. A JVM accepts a fixed range of major versions, up to the one of its own release, and refuses anything newer[1][3]. The message names both sides:
class file version 65.0is the class: it was compiled for Java 21.only recognizes class file versions up to 61.0is the JVM running it: Java 17.
So the jar was built with a newer JDK, or for a newer --release, than the Java that runs it. Nothing is wrong with the code; the two ends of the pipeline disagree on the Java version.
The text comes from the JVM itself, so its wording depends on the runtime: JDK 17, 21 and 25 print has been compiled by a more recent version of the Java Runtime[4][3][5]. The OpenJDK main line, which is version 28[8], words it differently, as requires a newer Java runtime. The runtime in use, Java 28, supports class file versions up to 72.0[7]. Both carry the same two numbers.
Class file version and Java release
The specification lists the major version that each Java SE release introduced[1][2]:
| Class file version | Java release |
|---|---|
| 52.0 | Java 8 |
| 55.0 | Java 11 |
| 61.0 | Java 17 |
| 65.0 | Java 21 |
| 69.0 | Java 25 |
The rows up to Java 21 are from the Java SE 21 specification’s table[1]; the Java SE 25 specification says a Java 25 JVM supports major versions 45 through 69[2]. From Java 5 on, every row of that table is the release number plus 44[1], the rule OpenJDK’s own build files use too[8], so class file version 66.0 would be Java 22 and 55.0 Java 11.
A minor version of 65535, as in 65.65535, marks a class compiled with preview features; it loads only on exactly that Java release, with preview features switched on[2].
Find which side is which
Check the Java that runs the program, on the machine or in the container where the error appears[10]:
java -version
Then check what built the jar. A jar made by Maven usually carries the JDK that ran the build in its manifest as Build-Jdk-Spec[12]:
unzip -p target/app.jar META-INF/MANIFEST.MF
If the class that fails is not yours but a library’s, the library was published for a newer Java than your runtime: the second fix below does not help, because you do not compile it.
Fix 1: run on a Java at least as new as the build
The fix that changes no code. Install a JRE or JDK of the release in the error, or newer, where the program runs. Each JVM supports every older class file version too[1], so a Java 21 runtime runs classes built for Java 8, 11, 17 or 21.
In a Dockerfile, this is the usual cause: the build stage and the run stage name different Java versions. Keep them the same:
FROM eclipse-temurin:21-jdk AS build
WORKDIR /src
COPY . .
RUN ./mvnw -q -DskipTests package # the project's Maven wrapper
FROM eclipse-temurin:21-jre
COPY --from=build /src/target/*.jar /app.jar
CMD ["java", "-jar", "/app.jar"]
Watch for an untagged image. eclipse-temurin with no tag, or :latest, is the Java 25 JDK today[16], so a build stage that names no version can compile for Java 25 while a run stage pinned to 17-jre cannot load the result.
Fix 2: compile for the older Java
When the runtime is fixed, tell the compiler to target it. Use --release, not -source and -target:
--releasecompiles under the language rules of that release, writes class files for it, and compiles against that release’s API[9].-sourceand-targetset only the language rules and the class file version[9]. Settingtargetdoes not guarantee that the code runs on a JRE of that version: a call to an API that exists only in a later Java fails at run time with a linkage error[11].
You cannot use --release together with -source or -target[9], and a JDK supports only a limited number of previous releases[9].
javac
javac --release 17 -d out $(find src -name '*.java')
Maven
Set the property[11]:
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>
or the plugin’s release parameter[11]:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>17</release>
</configuration>
</plugin>
Write 8, not 1.8[11]. JDK 8 itself has no --release; from compiler plugin 3.13.0 on, the plugin passes source and target instead when it runs on JDK 8[11]. If your pom.xml still sets maven.compiler.source and maven.compiler.target, release is the one to keep: the plugin’s docs say to use source and target only where release is not available[11].
Gradle
A toolchain picks the JDK that compiles, tests and builds javadoc[13]:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
Without one, Gradle builds with the Java that runs Gradle itself[13], which is how a newer JDK on a laptop or CI machine ends up in the class files. If no matching JDK is installed, Gradle can download one; that needs a download repository, for example the Foojay resolver plugin in settings.gradle.kts[13].
To build with a newer JDK but produce class files for an older Java, add options.release, as Gradle’s own example does with a Java 17 toolchain and Java 11 output[13]:
tasks.withType<JavaCompile>().configureEach {
options.release = 11
}
The toolchain covers Gradle’s own compile, test and javadoc tasks[13]; the java that runs your jar on the server is whatever is installed there. That runtime must still be at least the toolchain’s version, or the options.release one.
When the error comes from the build itself
If mvn package or gradle build stops with UnsupportedClassVersionError, the class that failed is a build plugin or a dependency, and the JDK running the build is too old for it. Spring Boot 3.0 requires Java 17[17], Spring Boot 3.5 at least Java 17[14], and Spring Boot 4.2 at least Java 17 as well[15]: so a Spring Boot 3 project cannot be built with JDK 11. A message with class file version 61.0 and up to 55.0 means exactly that pairing: something compiled for Java 17 loaded by a Java 11 runtime. Lowering release does not help here; build with Java 17 or newer.
How to confirm the fix locally
Run the jar on the Java your server has, not the one on your laptop. A container makes that one command:
docker run --rm -v "$PWD/target":/app eclipse-temurin:17-jre java -jar /app/app.jar
If it starts, the class files are loadable by Java 17. Swap the tag for the Java you deploy with.
On Livops
- Where it shows. At start, the deploy stops as
start_failed, and the error is on the Logs page with the app’s last words; a web app’s previous version keeps running. See The app did not start. From a build plugin, it stops asbuild_failed, with the error in the build log. See Build failed. - Which Java. Livops has Java 11, 17, 21 and 25, and builds a repository with
pom.xmlorbuild.gradleitself. Which of them builds and starts it is described in Spring Boot hosting. Settingmaven.compiler.releaseor a Gradle toolchain to the Java you target keeps your laptop and the deploy on the same version. - Your own Dockerfile. If the repository has a
Dockerfile, it is used. Inlivops.json,"builder": "dockerfile"says so explicitly; it is read when the project is created. Then the Java is the one in the images you name, so give the build stage and the run stage the same version, as in Fix 1. AFROM openjdk:line names images that were removed from Docker Hub: useeclipse-temurinwith the same version. A web app listens on the port in thePORTvariable. See Frameworks and livops.json. - The assistant explains. Next to the failed build, the assistant’s button reads the log and tells you what happened and how to fix it. See AI assistant.
Building and running a Spring Boot app in production, the JVM’s memory and the port included, is in Spring Boot hosting.
Questions
What does class file version 65.0 mean?
It is the class file format of Java 21. Every Java release has its own major class file version: 52 is Java 8, 55 is Java 11, 61 is Java 17, 65 is Java 21 and 69 is Java 25. The error names two numbers: the version the class was compiled for, and the newest version the running Java can load.
Should I upgrade Java or compile for the older version?
Upgrade the runtime when you can: it is the change that touches no code, and the JDK that compiled the class is the one it was tested with. Compile for the older release only when the runtime is fixed, for example a server you cannot change, and then use --release so the compiler also refuses APIs the older Java does not have.
What is the difference between --release and -source with -target?
--release 17 compiles against the Java 17 API and writes Java 17 class files in one option. -source and -target only set the language rules and the class file version, so code can still call a method that exists only in a newer Java and fail at run time. javac does not allow --release together with -source or -target.
Why do I get the error while running mvn package or gradle build?
Then a build plugin or a dependency, not your code, was compiled for a newer Java than the JDK running the build. Spring Boot 3.0, 3.5 and 4.2 all need at least Java 17, so building a Spring Boot 3 project with JDK 11 fails this way. Run the build with a newer JDK.
Does a Gradle toolchain change the Java that runs the app?
It changes the Java that Gradle uses for compiling, testing and javadoc, and it can download that JDK if none is installed. It does not decide which java runs your jar on the server, so the runtime there still has to be as new as the toolchain, or you add options.release for an older one.
How do I see which Java built a jar?
A jar made by Maven usually has Build-Jdk-Spec in META-INF/MANIFEST.MF, the version of the JDK that ran the build. The error message itself is more exact: the first number is the class file version of the class that failed to load.
Which Java versions does Livops have?
Java 11, 17, 21 and 25. For a Dockerfile project, the Java is the one in the image the Dockerfile names, so use the same version in the build stage and the run stage.
Sources
- Java Virtual Machine Specification, Java SE 21 — Chapter 4, The class File Format (docs.oracle.com). Checked .
- Java Virtual Machine Specification, Java SE 25 — Chapter 4, The class File Format (docs.oracle.com). Checked .
- OpenJDK 21 source — hotspot classFileParser.cpp (github.com). Checked .
- OpenJDK 17 source — hotspot classFileParser.cpp (github.com). Checked .
- OpenJDK 25 source — hotspot classFileParser.cpp (github.com). Checked .
- OpenJDK 21 source — sun/launcher/resources/launcher.properties (github.com). Checked .
- OpenJDK main line source — hotspot classFileParser.cpp (github.com). Checked .
- OpenJDK main line source — make/conf/version-numbers.conf (github.com). Checked .
- Oracle — The javac Command (JDK 21) (docs.oracle.com). Checked .
- Oracle — The java Command (JDK 21) (docs.oracle.com). Checked .
- Apache Maven Compiler Plugin — Setting the --release of the Java Compiler (maven.apache.org). Checked .
- Apache Maven Archiver — manifest entries (maven.apache.org). Checked .
- Gradle User Manual — Toolchains for JVM projects (docs.gradle.org). Checked .
- Spring Boot 3.5 — System Requirements (docs.spring.io). Checked .
- Spring Boot 4.2 — System Requirements (docs.spring.io). Checked .
- Docker Official Images — eclipse-temurin tags (github.com). Checked .
- Spring Boot 3.0 — Getting Started, System Requirements (docs.spring.io). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Java appRelated
- Spring Boot hosting in 2026: deploying a Java app built with Maven or GradleA Spring Boot app in production is one executable jar, a JVM sized to the container rather than the machine, the port from the environment and a build that fits the time limit. On Livops a repository with pom.xml or build.gradle is built into that jar and runs as a web app for 39 credits a month (39,000 so'm), with the heap set to 75% of the container's memory. Here is how Render, Railway, Fly.io, Heroku and a VPS compare.
- Docker hosting: how to deploy a Docker container or a DockerfileTo host a container you need a host that builds or pulls the image, starts its CMD, sends traffic to the port it listens on and stops it with SIGTERM. On Livops a Dockerfile at the root of the repository is built on Livops's servers and runs for 39 credits a month (39,000 so'm); a public image from Docker Hub, GHCR or Quay runs without a build. Here is what a container needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- exec format error in Docker: the image was built for another CPUThe kernel refused to run the container's program because it is not an executable for this machine: almost always a binary or image built for arm64 (an Apple Silicon Mac) running on an amd64 server, or the reverse. Build for the server's platform with --platform linux/amd64, or as a multi-platform image; if the file is a script, give it a #! line.
- go: go.mod requires go >= 1.24 (running go 1.22; GOTOOLCHAIN=local): how to fix itgo: go.mod requires go >= 1.24 (running go 1.22; GOTOOLCHAIN=local) means the go line in go.mod asks for a newer Go than the one running, and GOTOOLCHAIN=local forbids fetching another. Since Go 1.21 the go line is a hard minimum. Build with a Go at least that new, let GOTOOLCHAIN=auto download it, or lower the go line if your code and dependencies allow. toolchain not available means that download failed.
- App not listening on $PORT: why the health check failed after deployThe platform started your app, tried the port it gave it, and nothing answered in time. Almost always the app listens on its own fixed port instead of the PORT variable, listens on localhost (127.0.0.1) instead of 0.0.0.0, or crashed or was still starting when the check gave up. Listen on 0.0.0.0 and the port in PORT, and it passes.