The message
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
The first number is what the code needs. The second is what your server has. Translate them:
| Class file version | Java |
|---|---|
| 52.0 | Java 8 |
| 55.0 | Java 11 |
| 61.0 | Java 17 |
| 65.0 | Java 21 |
| 69.0 | Java 25 |
In the example above the application needs Java 21 but the server runs Java 17.
1. See which Java is used
java -version
update-alternatives --list java # Debian and Ubuntu
ps -o args= -p $(pgrep -f myapp.jar | head -1) | cut -d' ' -f1
Many servers have several Java versions installed. The one in your shell is not always the one the service uses. The last command shows the binary the running process was started with.
2. Install the right Java
Follow Install Java 21 on Ubuntu, or for another version, sudo apt install openjdk-17-jre-headless. Pick by LTS version.
3. Point the service at it
Spring Boot or any JAR service. In the systemd unit, give the full path to Java:
ExecStart=/usr/lib/jvm/java-21-openjdk-amd64/bin/java -jar /opt/myapp/app.jar
then sudo systemctl daemon-reload && sudo systemctl restart myapp.
Tomcat. Set JAVA_HOME. On Debian and Ubuntu packages put it in /etc/default/tomcat10:
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
For a tarball install, export JAVA_HOME=... in bin/setenv.sh. Restart Tomcat. Check the first lines of the log, which print the Java version in use.
4. Or compile for the older Java
If you must stay on an older Java, build with the matching release target. Maven: <maven.compiler.release>17</maven.compiler.release>. Gradle: java { toolchain { languageVersion = JavaLanguageVersion.of(17) } }. This works only if the code and its libraries do not use newer APIs. Spring Boot 3 needs Java 17 or newer, so downgrading below that is not possible without changing the framework version.
Questions about fix unsupportedclassversionerror
Can I run old class files on a newer Java?
Yes. Newer Java versions run older class files. The error only appears in the other direction.
Last updated October 29, 2026.