Play Framework Scala Hello-World 在 Ubuntu 20 上失败

clo*_*fin 10 scala playframework

基本的 Play Framework 示例 (play-scala-hello-world-tutorial) 在使用 OpenAdopt JDK 的 Ubuntu 20 上失败,但在 Macos 上运行良好。我的 Linux 设置有什么问题吗?

根据https://www.playframework.com/getting-started)我...

> git clone https://github.com/playframework/play-samples.git
> cd play-samples/play-scala-hello-world-tutorial
> sbt run  
    [info] welcome to sbt 1.4.3 (AdoptOpenJDK Java 16)
    [info] loading global plugins from /home/gp/.sbt/1.0/plugins
    [info] loading settings for project play-scala-hello-world-tutorial-build from plugins.sbt,scaffold.sbt ...
    [info] loading project definition from /home/.../play-samples/play-scala-hello-world-tutorial/project
    [warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
    [info] loading settings for project root from build.sbt ...
    [info] set current project to play-scala-hello-world-tutorial (in build file:/home/.../play-samples/play-scala-hello-world-tutorial/)

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.AkkaHttpServer - Listening for HTTP on /[0:0:0:0:0:0:0:0]:9000

(Server started, use Enter to stop and go back to the console...)
Run Code Online (Sandbox Code Playgroud)

卷曲本地主机:9000

结果是这样的:

play.api.UnexpectedException: Unexpected exception[UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item]
    at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:254)
    at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:148)
    at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:302)
    at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:224)
    at akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1297)
    at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
    at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:495)
    at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:390)
    at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:625)
    at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:502)
Caused by: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2051)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3951)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3974)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4958)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4964)
    at com.google.inject.internal.FailableCache.get(FailableCache.java:54)
    at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49)
    at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:155)
    at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:592)
    at com.google.inject.internal.AbstractBindingProcessor$Processor.initializeBinding(AbstractBindingProcessor.java:173)
Caused by: java.lang.IllegalStateException: Unable to load cache item
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:79)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.get(LoadingCache.java:34)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:294)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:258)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:207)
    at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:49)
    at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:156)
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:94)
Caused by: java.lang.ExceptionInInitializerError: null
    at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:104)
    at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
    at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:77)
    at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate(AbstractClassGenerator.java:332)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache$2.call(LoadingCache.java:54)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @5f574e3d
    at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:464)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate(AbstractClassGenerator.java:339)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache$2.call(LoadingCache.java:54)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:61)
    at com.google.inject.internal.cglib.core.internal.$LoadingCache.get(LoadingCache.java:34)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:294)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @5f574e3d
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
    at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:61)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
    at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:52)
    at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:67)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:77)
    at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)


>java -version  
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment AdoptOpenJDK (build 16+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 16+36, mixed mode, sharing)
    
> sbt sbtVersion
[info] welcome to sbt 1.3.13 (AdoptOpenJDK Java 16)
[info] loading global plugins from /home/../.sbt/1.0/plugins
[info] loading settings for project play-scala-hello-world-tutorial-build from scaffold.sbt,plugins.sbt ...
[info] loading project definition from /home/.../play-samples/play-scala-hello-world-tutorial/project
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] loading settings for project root from build.sbt ...
[info] set current project to play-scala-hello-world-tutorial (in build file:/home/.../play-samples/play-scala-hello-world-tutorial/)
[info] 1.3.13
Run Code Online (Sandbox Code Playgroud)

项目/构建.属性:

# sbt.version=1.3.13
sbt.version=1.4.3
Run Code Online (Sandbox Code Playgroud)

Pro*_*fJS 6

我在JDK-11上遇到了同样的问题

尝试使用Java8解决了这个问题。

  • 不,我不。但事实上,我再次尝试使用“JDK-11”并且它有效。(我相信这是缓存或类似问题的问题)从头开始,我做了什么: - 克隆存储库 - &gt;“播放示例” - 检查我的 Java 版本(“JDK-11”)。另外,检查我的“JAVA_HOME”是否也设置为“JDK-11”,因为我在 iOS 上并使用 jenv,有时它没有正确设置“JAVA_HOME”。我还检查了 IntelliJ 上的项目正在使用 `JDK-11` - `sbt clean` - `sbt run` 并点击 `http://localhost:9000` (3认同)
  • 你现在知道为什么jdk 11不被允许吗?[播放要求](https://www.playframework.com/documentation/2.8.x/Requirements) 是 Java SE 1.8 **或更高版本** (2认同)
  • 顺便说一句,对于 JDK-17,请参阅 https://discuss.lightbend.com/t/play-sample-on-windows-java-lang-illegalstateexception-unable-to-load-cache-item/8663/2。 (2认同)

Div*_*shu 5

Play 2.8.16 依赖于 google Guice 版本4.2.3,该版本仅支持 jdk 14,要使其在 java 17 上运行,您需要将以下代码片段添加到您的build.sbt中

dependencyOverrides ++= Seq(
  "com.google.inject" % "guice" % "5.1.0",
  "com.google.inject.extensions" % "guice-assistedinject" % "5.1.0")
Run Code Online (Sandbox Code Playgroud)

您可以查看以下几个链接:-

  1. https://github.com/google/guice/wiki/Guice423
  2. https://github.com/google/guice/wiki/Guice510
  3. https://github.com/playframework/playframework/releases/2.8.15

添加上面的代码片段将使其能够在 17 上运行。