| この記事の要点 |
|
このエラーの典型
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/example/App 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 52.0
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
...
意味: 「このクラスファイルは Java 17 でコンパイルされている (61.0) が、実行している JRE は Java 8 (52.0) までしか読めません」。
class file version 対応表
| major version | Java バージョン | LTS |
|---|---|---|
| 52.0 | Java 8 | ○ |
| 53.0 | Java 9 | × |
| 54.0 | Java 10 | × |
| 55.0 | Java 11 | ○ |
| 56.0 | Java 12 | × |
| 57.0 | Java 13 | × |
| 58.0 | Java 14 | × |
| 59.0 | Java 15 | × |
| 60.0 | Java 16 | × |
| 61.0 | Java 17 | ○ |
| 62.0 | Java 18 | × |
| 63.0 | Java 19 | × |
| 64.0 | Java 20 | × |
| 65.0 | Java 21 | ○ |
原因の確認
# 実行時 Java バージョン
java -version
# openjdk version "1.8.0_362" ← Java 8
# コンパイル時 Java バージョン
javac -version
# javac 17.0.5 ← Java 17
# クラスファイルの version を直接見る
javap -v App.class | grep "major version"
# major version: 61
# または file コマンド
file App.class
# App.class: compiled Java class data, version 61.0 (Java SE 17)
対処 1: 実行時 JRE を上げる
最も素直な解決。サーバの JRE を最新 LTS に上げます:
# CentOS / RHEL
sudo yum install java-17-openjdk
# Ubuntu / Debian
sudo apt install openjdk-17-jre
# 複数バージョン共存時は alternatives で切替
sudo alternatives --config java
# macOS (Homebrew)
brew install openjdk@17
# 環境変数
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export PATH=$JAVA_HOME/bin:$PATH
対処 2: コンパイル時のターゲットを下げる
サーバ JRE を上げられない場合(古い環境への配布等)はコンパイル側を合わせます:
# Java 11 で動かしたい場合 (Java 17 でコンパイル中)
# --release 推奨 (Java 9+)
javac --release 11 App.java
# 古い書き方
javac -source 11 -target 11 -bootclasspath /path/to/jdk11/jre/lib/rt.jar App.java
Maven の設定
<!-- pom.xml -->
<properties>
<!-- 推奨: release で 1 か所指定 -->
<maven.compiler.release>11</maven.compiler.release>
<!-- 古い書き方 (source / target) -->
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
Gradle の設定
// build.gradle
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
// または toolchain (Gradle 6.7+, 推奨)
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
// Kotlin DSL (build.gradle.kts)
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks.withType<JavaCompile> {
options.release.set(11)
}
IDE での設定確認
| IDE | 確認場所 |
|---|---|
| IntelliJ IDEA | File → Project Structure → Project SDK / Language level / Modules → Sources の Language level |
| Eclipse | Window → Preferences → Java → Compiler → Compiler compliance level、+ プロジェクト Properties → Java Compiler |
| VS Code | java.configuration.runtimes + java.compile.nullAnalysis.mode 設定 |
Tomcat / アプリサーバで起きた場合
Tomcat 自体が古い Java で動いていると、WAR 内の Java 17 クラスを読めずに 500 エラーになります:
# Tomcat が使う Java を確認
ps -ef | grep tomcat
# /usr/lib/jvm/java-8-openjdk/bin/java ... org.apache.catalina.startup.Bootstrap
# CATALINA_HOME/bin/setenv.sh で明示
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export PATH=$JAVA_HOME/bin:$PATH
# Tomcat 再起動
systemctl restart tomcat
FAQ
Q: 依存ライブラリの jar が新しい Java でコンパイルされていて読めない
A: ライブラリの古いバージョンを使うか、自分のアプリも合わせて Java を上げる以外にありません。
Q: --release 8 と -source 8 -target 8 の違い
A: --release は API も Java 8 に縛る(新 API 呼び出しがコンパイルエラーになる)。-source -target は bytecode だけ古くする(実行時 NoSuchMethodError の危険)。
Q: Android で起きた
A: Android Gradle Plugin の compileOptions.sourceCompatibility / targetCompatibility を Java 8 / 11 に。
子ページ
子ページはありません
同階層のページ
- java.lang.IllegalStateException: CGLIB is required to process @Configuration classes
- Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
- No mapping found for HTTP request with URI ... in DispatcherServlet with name ...
- An internal error occurred during: "Building UI model". com/google/common/base/Function
- No identifier specified for entity : ...
- org.hibernate.hql.internal.ast.QuerySyntaxException: table_name is not mapped
- No compiler is provided in this environment
- java.sql.SQLException: The server time zone value ' ... ' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone
- Caused by: java.lang.RuntimeException: Executing an update/delete query
- Not supported for DML operations
- Field ... required a bean of type ... that could not be found.
- Annotation-specified bean name 'xxxController' for bean class [com.xxx.controller.xxxController] conflicts with existing, non-compatible bean definition of same name and class [com.xxx.xxxController]
- Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
- Exception in thread "main" java.lang.UnsupportedClassVersionError
人気ページ
- 1 Eclipseで「サーバーに追加または除去できるリソースがありません。」の原因と対処法
- 2 tomcat の起動 / 停止ログと catalina.log・catalina.out の違い
- 3 JavaScript で base URL を取得する方法|window.location.origin
- 4 YouTube Data API v3 エラー一覧|403・400・404 の原因と対処
- 5 Laravel エラー一覧|500/Blade/DB 接続/ルーティングの代表エラー
- 6 3Dグラフィックスとは|モデリング/レンダリング/主要ソフトウェア (Blender / Maya)
- 7 Spring Frameworkのアノテーション一覧
- 8 【Spring】@Valueアノテーションとは
- 9 CATALINA_HOME の確認方法 (Linux / Mac)
- 10 【Spring】@Autowiredアノテーションとは
最近更新/作成されたページ
- プロジェクトをTomcatプロジェクトとして認識させる方法 2026-10-07 22:32:50
- MySQLの1366 Incorrect string value|Laravelの文字コード・絵文字エラー 2026-10-07 21:54:03
- curlの証明書ホスト名不一致|旧エラー51・現行60の確認と対処 2026-10-07 21:54:03
- LaravelのMassAssignmentException|fillableの原因と安全な対処 2026-10-07 21:54:03
- Eclipse で Tomcat の起動ログがコンソールに出ない時の確認手順 2026-10-07 21:54:02
- MySQLにおける中央値(Median)の導き方(バージョン8未満) 2026-10-07 13:49:45
- getInputForward 2026-10-07 13:41:15
- JSONから配列に変換 2026-10-07 13:41:15
- ビューから値をモデルに格納しコントローラーで受け取る方法 2026-10-07 13:23:41
- Laravelのテーブル作成と定義変更|マイグレーション・up/down・注意点 2026-10-07 13:23:41
- NumPy 配列に要素を追加する方法 (append / concatenate) 2026-10-07 13:23:41
- MariaDB・MySQLで現在日時を取得する方法|NOW・タイムゾーン・保存型 2026-10-07 13:13:36
- 【django】テンプレートで定数を使用する方法 2026-10-07 13:10:15
- Spring BootにおけるApplication.propertiesの環境依存設定の分割方法 2026-10-07 12:09:35
- Not supported for DML operations【Springエラー】 2026-10-07 11:09:38