Search code examples
playframeworkplayframework-2.2

Unsupported class file major version 58 on Play Java Starter Example when using Ebean


I am testing Play, am using Oracle Java 1.8. When I download the Play Java Starter example and enable Ebean with a single model, I get a:

Unsupported class file major version 58

Error. On my plugins.sbt I have:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "6.0.0")

and am using all the defaults from Play. This used to work before, but as of recently it does not work. I believe "guice" or "Ebean's injection" or a dependency has been compiled with Java 14. Also, when I place in the JavaOptions the following:

    javacOptions ++= Seq(
      "-source", "1.8", "-target", "1.8",
      ...

The compiler breaks saying there is code compiled with Java 14. Does anyone else get this problem? So far I have tried different permutations of the Play Framework, Ebean, Scala, and other versions. I believe if you clear your sbt and gradle cache you'll get the same error.


Solution

  • After formatting my hard drive thinking I was insane, it turns out that the newest version of SBT uses OpenJDK 14 (or the latest version) to do compilations or injections. I believe this is the case because Oracle JKD is no longer available in public facing repositories but requires one to create an Oracle account to download their JDK.

    The BEST solution is to set a $JAVA_HOME on your terminal (i.e.: add it to .bashrc) to force SBT to use your preferred JDK. Any other way will result in SBT using the latest OpenJDK version.