Play Framework Scala Hello-World fail on Ubuntu 20 - scala

The basic Play Framework sample (play-scala-hello-world-tutorial) fails on Ubuntu 20 with OpenAdopt JDK but works fine on Macos. Is there something arry with my Linux setup?
Per https://www.playframework.com/getting-started) I...
> 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...)
curl localhost:9000
results in this:
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
project/build.properties:
# sbt.version=1.3.13
sbt.version=1.4.3

I was having the same issue with JDK-11
Trying with Java8 solved the issue.

For me is the opposite of #ProofJS's solution. On Windows 10,
JDK8 would not work (it would not compile - sbt compile). JDK 11 worked without problems. JDK 17 did compile, but would not run - sbt run.
welcome to sbt 1.3.13 (Oracle Corporation Java 11.0.12)
In IntelliJ, in the context menu for the project (right click) -> Open Module Settings -> Project -> SDK 11.0.12.
build.properties (file):
sbt.version=1.3.13
plugins.sbt (file):
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.11")
build.sbt (file):
lazy val root = (project in file("."))
.enablePlugins(PlayScala)
.settings(
name := """play-scala-forms-example""",
version := "2.8.x",
scalaVersion := "2.13.7",
libraryDependencies ++= Seq(
guice,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-Xfatal-warnings"
)
)
System Env: JAVA_HOME & Path set to JDK-11/bin

Play 2.8.16 is dependent on google Guice version 4.2.3, which only support jdk 14, to make this run with java 17, you need to add the following code snippet into your build.sbt
dependencyOverrides ++= Seq(
"com.google.inject" % "guice" % "5.1.0",
"com.google.inject.extensions" % "guice-assistedinject" % "5.1.0")
Here are few links you can have a look :-
https://github.com/google/guice/wiki/Guice423
https://github.com/google/guice/wiki/Guice510
https://github.com/playframework/playframework/releases/2.8.15
Adding the above snippet code would make it able to run with 17.

Related

chisel compilation error: object plugin is not a member of package chisel3.internal

I am studying chisel3 with a small trial project.
I finished code, fixed several syntax issues in compilation, then, it reported an error without indicating error file and line number.
$ sbt test
[info] welcome to sbt 1.4.9 (Red Hat, Inc. Java 1.8.0_292)
[info] loading settings for project fparser-build from plugins.sbt ...
[info] loading project definition from /mnt/disk1/yupeng/repos/fparser/project
[info] loading settings for project root from build.sbt ...
[info] set current project to fparser (in build file:/mnt/disk1/yupeng/repos/fparser/)
[info] compiling 3 Scala sources to /mnt/disk1/yupeng/repos/fparser/target/scala-2.12/classes ...
[error] ## Exception when compiling 3 sources to /mnt/disk1/yupeng/repos/fparser/target/scala-2.12/classes
[error] scala.reflect.internal.Types$TypeError: object plugin is not a member of package chisel3.internal
[error]
[error]
[error] scala.reflect.internal.Types$TypeError: object plugin is not a member of package chisel3.internal
[error] (Compile / compileIncremental) scala.reflect.internal.Types$TypeError: object plugin is not a member of package chisel3.internal
[error] Total time: 3 s, completed Jul 16, 2021 4:38:42 PM
what does it mean? please help.
I just found, the error is gone after I changed chisel3 versions in build.sbt.
libraryDependencies ++= Seq(
"edu.berkeley.cs" %% "chisel3" % "3.4.3",
// "edu.berkeley.cs" %% "chisel3" % "3.2.6", // this one generate plugin error above
"edu.berkeley.cs" %% "chiseltest" % "0.3.3" % "test",
"edu.berkeley.cs" %% "rocketchip" % "1.2.6"
Previously I changed from 3.4.3 to 3.2.6 because sbt warning of
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
I ran sbt evicted and it said rocketchip 1.2.6 should use chisel3 3.2.6.
Maybe someone can clarify.

NoClassDefFoundError when running a Scala/Swing program with sbt

I am trying to compile an old school project from around March, 2015. I haven’t touched it since then. The project is written in Scala with the Swing library, and the build tool is sbt.
Apparently my build.sbt file needs updating. After digging the Internet, I found that this configuration should work.
lazy val root = (project in file (".")).
settings (
name := "MyProgram",
/* FORMERLY: */
//libraryDependencies += "org.scala-lang" % "scala-swing" % "2.10+",
//ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
/* NOW: */
scalaVersion := "2.13.0",
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "2.1.1"
)
The trick would be to use compatible versions of Scala and Swing. I tried the following pairs, which I expected to work together (either because I saw them on the webpage of package Swing, or because it worked for other people on SO):
(Scala 2.13.0, Swing 2.1.1)
(Scala 2.12.6, Swing 2.1.1)
(Scala 2.12.1, Swing 2.0.0-M)
(Scala 2.11.1, Swing 1.0.2)
I also tried switching from Java 12 (jdk-openjdk 12.0.2.u10-1) to Java 8 (jdk8-openjdk 8.u222-2).
However, all combinations give the same error. Compiling (sbt compile) works fine, but running the application (sbt run) results in a bunch of NoClassDefFoundError / ClassNotFoundException errors:
$ sbt run
[info] Loading project definition from /home/me/MyProject/project
[info] Loading settings for project root from build.sbt ...
[info] Set current project to MyProject (in build file:/home/me/MyProject/)
[info] Compiling 22 Scala sources to /home/me/MyProject/target/scala-2.12/classes ...
[warn] there were four deprecation warnings (since 2.12.0); re-run with -deprecation for details
[warn] one warning found
[info] running Main.Main
[error] java.lang.NoClassDefFoundError: scala/swing/event/WindowOpened
[error] at scala.swing.Window$$anon$1.windowOpened(Window.scala:80)
...
[error] Caused by: java.lang.ClassNotFoundException: scala.swing.event.WindowOpened
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
...
[error] java.lang.NoClassDefFoundError: scala/swing/event/WindowActivated
[error] at scala.swing.Window$$anon$1.windowActivated(Window.scala:74)
...
[error] Caused by: java.lang.ClassNotFoundException: scala.swing.event.WindowActivated
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
...
The application’s main window shows up but is pretty unusable, with every GUI element generating more errors when activated; even trying to close the window via the window manager fails.
What is missing to run this program?

scala "console" command gives error "Missing scala-library.jar"

Under sbt, if I give "console" to start a REPL shell, I get the following error.
[error] stack trace is suppressed; run 'last scalaInstance' for the full output
[error] (scalaInstance) Missing scala-library.jar
[error] Total time: 1 s, completed Oct 7, 2019 12:45:07 PM
$ sbt scalaVersion
[info] Loading global plugins from C:..\plugins
[info] Loading settings for project test from plugins.sbt ...
[info] Loading project definition from C:xx\test\project
[info] Loading settings for project root from build.sbt ...
[info] scalaVersion
[info] 2.11.12
$ sbt sbtVersion
[info] sbtVersion
[info] 1.3.0
Try
assemblyOption in set: = (assemblyOption in set) .value.copy (includeScala = true)
Source: https://github.com/sbt/sbt-assembly
if this doesn't solve the issue, it could be a compatibility issue with a plugin which you might have installed, it means that you would have to delete the plugin directory in %HOME%. and %HOME%.ivy2 because it caches some artifacts locally.
If you are not able to find the plugin try deleting %HOME%.ivy2 and running the console again, as it will remove the cached artifacts.
You might want to refer
https://pt.coredump.biz/questions/50313823/why-does-running-tests-through-jenkins-user-on-build-slave-fail-with-missing-scalalibraryjar
I hope it helps.
Somewhat unrelated but I ran into this error on one of my projects and deleting all caches (.m2, .ivy2, coursier) was not enough to fix this. I also had to clear out my .sbt folder (I assume emptying the boot directory). Be sure to backup any settings you still might need.
can you try updating scala version in your sbt build?
for example,
scalaVersion := "2.13.0"

SBT gives "class file has wrong version 51.0, should be 49.0" when compiling a mixed project?

EDIT: Various SBT options
show scalacOptions
List(-deprecation, -unchecked, -encoding, UTF-8, -Yinline-warnings, -feature)
show javaOptions
List()
about
[info] This is sbt 0.13.1
[info] The current project is {file:/Users/ThomasNorth/Documents/CODE/SERVER/MonetiseAlpha/monetise-webserver/}monetise-webserver 1.0.0-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info]
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
I am getting the following error when attempting to compile a scala project with some java sources, the error is as follows
[error] /Users/ThomasNorth/Documents/CODE/SERVER/MonetiseAlpha/monetise-webserver/src/main/java/com/boxbe/pub/email/EmailAddress.java:31: cannot access java.util.regex.Pattern
[error] bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/util/regex/Pattern.class)
[error] class file has wrong version 51.0, should be 49.0
[error] Please remove or make sure it appears in the correct subdirectory of the classpath.
[error] import java.util.regex.Pattern;
[error] ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] Total time: 13 s, completed 28/02/2014 3:36:38 PM
The thing is, both javac and java are updated to their latest versions
javac -version
javac 1.7.0_51
javac: no source files
Usage: javac <options> <source files>
where possible options include:
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
build.sbt
organization := "com.monetise"
name := "webserver"
version := "1.0.0-SNAPSHOT"
scalaVersion := "2.10.3"
resolvers ++= Seq(
Resolver.sonatypeRepo("release"),
Resolver.sonatypeRepo("snapshots"),
"Untyped" at "http://ivy.untyped.com/com.untyped/"
)
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-encoding", "UTF-8",
"-Yinline-warnings",
"-feature"
// "-Xcheckinit" // for debugging only, see https://github.com/paulp/scala-faq/wiki/Initialization-Order
// "-optimise" // this option will slow your build
)
And I only have a single sdk installed, which is located at /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
Anyone have any ideas why this is happening?
I have even attempted to put this in my globals.sbt
javaHome := Some(file("/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"))
To force the java home. SBT is v 0.13.1
System is Mac Osx 10.9.2 (Mavericks)
You can't use the javaHome setting to specify the version of java used to launch sbt, that will only specify which JDK sbt will look in, and which binaries it will use when it forks. Unfortunately, the startup scripts for sbt dont' know how to look at this javaHome setting and update themselves.
What sbt script are you using? Can you add a which sbt output, and show us the contents of this script? Most likely this file is pulling the MacOSX native JDK and not the one you've installed.

How to use sbt-scalabuff plugin with sbt 0.13?

I am trying to use sbt-scalabuff plugin, but sbt keeps complaining that the plugin cannot be found.
The plugin documentation does not state out a resolver url, either. Is the plugin deprecated or my Scala version is not supported?
Details:
com.github.sbt:sbt-scalabuff:0.2 (sbtVersion=0.13, scalaVersion=2.10)
Here is my plugins.sbt:
libraryDependencies += "net.sandrogrzicic" %% "scalabuff-runtime" % "1.3.6"
addSbtPlugin("com.github.sbt" %% "sbt-scalabuff" % "0.2")
Here is part of the stack trace:
sbt.ResolveException: unresolved dependency: com.github.sbt#sbt-scalabuff;0.2: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:213)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:116)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:116)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:104)
at sbt.IvySbt.sbt$IvySbt$$action$1(Ivy.scala:51)
at sbt.IvySbt$$anon$3.call(Ivy.scala:60)
...
[error] (*:update) sbt.ResolveException: unresolved dependency: com.github.sbt#sbt-scalabuff;0.2: not found
The sbt-scalabuff plugin does not have the plugin jar published to any known repository sbt could use for your configuration - sbtVersion=0.13 and scalaVersion=2.10.
I also doubt the plugin supports sbt 0.13 (few attempts of mine failed miserably when I compiled the plugin myself to use the version).
It seems that your only options are to downgrade sbt to 0.12.4 or migrate the plugin to 0.13.
Since the plugin has been published to the Resolver.sbtPluginRepo("releases") repository, i.e. http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases as http://dl.bintray.com/sbt/sbt-plugin-releases/com.github.sbt/sbt-scalabuff/scala_2.10/sbt_0.12/ you will have to use the version of sbt.
Use the following in project/sbt-scalabuff.sbt:
addSbtPlugin("com.github.sbt" %% "sbt-scalabuff" % "0.2")
You should then specify the version of sbt in project/build.properties as follows:
sbt.version=0.12.4
or just use sbt-launch 0.12.4.
When in sbt console, you can use the scalabuff task or the settings: scalabuff-version, scalabuff-main and scalabuff-args.
> sbt-version
[info] 0.12.4
> about
[info] This is sbt 0.12.4
[info] The current project is {file:/Users/jacek/sandbox/sbt-scalabuff-test-project/}main
[info] The current project is built against Scala 2.9.2
[info] Available Plugins: org.sbtidea.SbtIdeaPlugin, com.timushev.sbt.updates.UpdatesPlugin, scalabuff.ScalaBuffPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
> scalabuff-version
[info] 1.1.1
> help scalabuff
Generate Scala sources from protocol buffers definitions
> scalabuff-args
[info] List()
> scalabuff-main
[info] net.sandrogrzicic.scalabuff.compiler.ScalaBuff
See the scalabuff.ScalaBuffPlugin object in the GitHub repository.
I also had to change the build object (as described in the Usage section) to set up a project with the plugin to import sbt._:
import sbt._
import scalabuff.ScalaBuffPlugin._
object build extends Build {
lazy val root = Project(
"main",
file("."),
settings = Defaults.defaultSettings ++ scalabuffSettings
).configs(ScalaBuff)
}