I changed my application from Java 8 to Java 9. Changed the Windows system environment variable (path) and the JAVA_HOME to Java 9 (jdk-9.0.1).
When running the application in the IDE (IntelliJ) it works fine. It also compiles without problems with sbt. Just running the application with docker doesn't work.
The application seems to be compiled successfully with Java 9 but docker tries to run it with Java 8 (this is what I read from the exception message).
Commands:
sbt docker:publish
docker run --rm -p 9000:9000 eu.gcr.io/the-repository-name/the-image-name:1.0
I get the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
Module has been compiled by a more recent version of the
Java Runtime (class file version 53.0), this version of the
Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at play.api.inject.Modules$.locate(Module.scala:119)
at play.api.inject.guice.GuiceableModule$.loadModules(GuiceInjectorBuilder.scala:276)
at play.api.inject.guice.GuiceApplicationBuilder$.$anonfun$$lessinit$greater$default$9$1(GuiceApplicationBuilder.scala:30)
at play.api.inject.guice.GuiceApplicationBuilder.applicationModule(GuiceApplicationBuilder.scala:102)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:51)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:25)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
What do I have to do, that Docker uses Java 9?
java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
docker version
Client:
Version: 17.10.0-ce
API version: 1.33
Go version: go1.8.3
Git commit: f4ffd25
Built: Tue Oct 17 19:00:02 2017
OS/Arch: windows/amd64
Server:
Version: 17.10.0-ce
API version: 1.33 (minimum version 1.12)
Go version: go1.8.3
Git commit: f4ffd25
Built: Tue Oct 17 19:05:23 2017
OS/Arch: linux/amd64
Experimental: true
答案 0 :(得分:2)
错误意味着您正在尝试在较旧版本的Java(具有类52.0版本的8)中运行使用较新版本的Java(9具有类版本53.0)编译的代码。因此,您的docker镜像可能已安装Java 8。让我们做一些侦探工作。 : - )
如果我理解正确,您使用sbt-native-packager生成Docker镜像。如果是这样,sbt-native-packager正在使用openjdk:latest
图像作为基本图像,如下所示:
版本1.3.1是Play 2.6.7使用的版本,您也可以在此处看到:
https://github.com/playframework/playframework/blob/2.6.7/framework/project/plugins.sbt#L8
问题是openjdk:latest
图像使用Java 8.您可以通过查看latest
代码linked at the image page来确认。这是代码:
鉴于此,您可能希望更改dockerBaseImage
以使用使用Java 9的基本映像,例如:
dockerBaseImage := "9-jdk"
您可以在此处查看完整的图片版本列表:https://hub.docker.com/_/openjdk/