ablog

不器用で落着きのない技術者のメモ

Amazon DynamoDB Accelerator (DAX) のサンプル Java アプリを実行すると "Unsupported major.minor version 52.0" と怒られる

Java と DAX - Amazon DynamoDB のサンプルJavaアプリを実行したら、"Unsupported major.minor version 52.0" と怒られたので解決策をメモ。

事象

$ java TryDax
Exception in thread "main" java.lang.UnsupportedClassVersionError: TryDax : Unsupported major.minor version 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:808)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:443)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:65)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:349)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:348)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:430)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:323)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

解決策

  • Java のバージョンを確認
$ java -version
java version "1.7.0_201"
OpenJDK Runtime Environment (amzn-2.6.16.0.78.amzn1-x86_64 u201-b00)
OpenJDK 64-Bit Server VM (build 24.201-b00, mixed mode)
  • Java のバージョンを 1.8 に変更
$ sudo update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number: 2
  • Javac は 1.8 だったのでそのまま
$ sudo update-alternatives --config javac

There is 1 program that provides 'javac'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac

Enter to keep the current selection[+], or type selection number: 1
$ javac TryDax*.java
warning: Supported source version 'RELEASE_7' from annotation processor 'com.amazonaws.eclipse.simpleworkflow.asynchrony.annotationprocessor.AsynchronyDeciderAnnotationProcessor' less than -source '1.8'
1 warning
  • サンプルアプリを実行する
$ java TryDax
Creating a DynamoDB client
Creating table...
Attempting to create table; please wait...
Sep 29, 2019 8:10:05 AM com.amazonaws.profile.path.cred.CredentialsLegacyConfigLocationProvider getLocation
WARNING: Found the legacy config profiles file at [/home/ec2-user/.aws/config]. Please move it to the latest default location [~/.aws/credentials].
Successfully created table.  Table status: ACTIVE
Populating table...
Writing data to the table...
Writing 10 items for partition key: 1
Writing 10 items for partition key: 2
Writing 10 items for partition key: 3
Writing 10 items for partition key: 4
Writing 10 items for partition key: 5
Writing 10 items for partition key: 6
Writing 10 items for partition key: 7
Writing 10 items for partition key: 8
Writing 10 items for partition key: 9
Writing 10 items for partition key: 10
Running GetItem, Scan, and Query tests...
First iteration of each test will result in cache misses
Next iterations are cache hits

GetItem test - partition key 1 and sort keys 1-10
	Total time: 76.314 ms - Avg time: 7.631 ms
	Total time: 61.295 ms - Avg time: 6.130 ms
	Total time: 72.975 ms - Avg time: 7.298 ms
	Total time: 53.670 ms - Avg time: 5.367 ms
	Total time: 50.510 ms - Avg time: 5.051 ms
Query test - partition key 5 and sort keys between 2 and 9
	Total time: 9.622 ms - Avg time: 1.924 ms
	Total time: 8.949 ms - Avg time: 1.790 ms
	Total time: 5.223 ms - Avg time: 1.045 ms
	Total time: 7.567 ms - Avg time: 1.513 ms
	Total time: 7.285 ms - Avg time: 1.457 ms
Scan test - all items in the table
	Total time: 28.724 ms - Avg time: 5.745 ms
	Total time: 19.273 ms - Avg time: 3.855 ms
	Total time: 14.883 ms - Avg time: 2.977 ms
	Total time: 16.374 ms - Avg time: 3.275 ms
	Total time: 18.015 ms - Avg time: 3.603 ms

Attempting to delete table; please wait...
Successfully deleted table.