I'm using Play Framework, Akka Persistent actors and MongoDB.
When I run my Specs2 Test with FakeApplication, java.lang.ExceptionInInitializerError is thrown and the cause is the following:
Caused by: #6md6ke2n9: ReactiveMongoPlugin Error
at play.modules.reactivemongo.ReactiveMongoPlugin$.current(ReactiveMongoPlugin.scala:83)
at play.modules.reactivemongo.ReactiveMongoPlugin$.db(ReactiveMongoPlugin.scala:78)
at models.daos.TaskDAO$.<init>(TaskDAO.scala:25)
at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)
This occurs when ReactiveMongoPlugin.db is invoked.
def db: reactivemongo.api.DB = ReactiveMongoPlugin.db
val futureCollection: Future[JSONCollection] = {
val db = ReactiveMongoPlugin.db
// ...
}
This problem has occurred since I started using PersistentActor. I don't know if there is some conflict between akka-persistence and reactive-mongo dependencies. The following is my build.sbt:
name := "fmcloud"
version := "0.1"
scalaVersion := "2.11.6"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value
resolvers += Resolver.sonatypeRepo("snapshots")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases"
libraryDependencies ++= Seq(
"javax.inject" % "javax.inject" % "1",
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23",
"net.codingwell" %% "scala-guice" % "4.0.0-beta5",
"org.webjars" % "bootstrap" % "3.3.1",
"org.webjars" % "angularjs" % "1.3.8",
"org.webjars" % "angular-ui-bootstrap" % "0.12.0",
"org.mockito" % "mockito-core" % "1.10.17" % "test",
"com.mohiva" %% "play-silhouette-testkit" % "2.0" % "test",
"com.mohiva" %% "play-silhouette" % "2.0",
"org.json" % "json" % "20141113",
"javax.websocket" % "javax.websocket-client-api" % "1.1",
"org.glassfish.tyrus" % "tyrus-container-grizzly-client" % "1.4",
"com.typesafe.akka" % "akka-testkit_2.11" % "2.3.10",
"com.typesafe.akka" % "akka-persistence-experimental_2.11" % "2.3.10",
"com.github.ironfish" %% "akka-persistence-mongo-casbah" % "0.7.5" % "compile"
)
EDIT: Proably this was an IntelliJ IDEA issue. I updated both IntelliJ and Scala plugin and now there is no ReactiveMongoPlugin Error. Unfortunately now all test-cases work except one (which involves the PersistentActor).
It is still thrown java.lang.ExceptionInInitializerError but the cause is different:
Caused by: java.lang.RuntimeException: There is no started application
at scala.sys.package$.error(package.scala:27)
at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
at scala.Option.getOrElse(Option.scala:121)
at play.api.Play$.current(Play.scala:71)
at models.daos.TaskDAO$.<init>(TaskDAO.scala:26)
at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)
... 19 more
EDIT2: I noticed that this error occurs only when I use TestActorRef of my persistent actor.
Related
Test project Build.sbt
scalaVersion := "2.12.8"
crossScalaVersions := Seq("2.11.12", "2.12.8")
val scalaTestVersion = "3.0.5"
val rocksDBVersion = "5.17.2"
val kafkaVersion = "2.2.0"
lazy val deps = Seq(
// "javax.ws.rs" % "javax.ws.rs-api" % "2.1" jar(),
"org.apache.kafka" % "kafka-clients" % kafkaVersion,
"org.apache.kafka" % "kafka-clients" % kafkaVersion classifier "test",
"org.apache.kafka" % "kafka-streams" % kafkaVersion,
"org.apache.kafka" % "kafka-streams" % kafkaVersion classifier "test",
"org.apache.kafka" %% "kafka" % kafkaVersion,
"org.apache.kafka" % "kafka-streams-test-utils" % kafkaVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.rocksdb" % "rocksdbjni" % rocksDBVersion % "test"
)
Test Project plugins.sbt
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.8")
This is my Test application sbt configuration file and when I run sbt package it will create a jar file for me then I have to use that jar in my other project.
Other project sbt file
scalaVersion := "2.12.6"
object Dependencies {
val deps = Seq(
"org.json4s" %% "json4s-native" % "3.5.3",
"ch.qos.logback" % "logback-classic" % "1.2.3",
"cool.graph" % "cuid-java" % "0.1.1",
"org.apache.kafka" % "kafka-streams" % "2.2.0",
"com.typesafe" % "config" % "1.3.3",
"org.scalaz" %% "scalaz-core" % "7.2.20",
"org.apache.commons" % "commons-lang3" % "3.8.1",
//Test
"org.scalatest" %% "scalatest" % "3.0.4" % Test,
"org.mockito" % "mockito-all" % "1.10.19" % Test,
"com.abc" %% "kafka-streams-test-kit" % "2.2.0" % Test
)
}
Other Project plugins.sbt
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.8")
As I'm new in Scala and I don't know what i did wrong in that as when i put my test scala jar into another project It will give me the error.
Error:-
java.lang.NoClassDefFoundError: scala/Product$class
[error] at com.shepherd.kafka.streams.test.kit.MockedStreams$Builder.<init>(MockedStreams.scala:17)
[error] at com.shepherd.kafka.streams.test.kit.MockedStreams$.apply(MockedStreams.scala:15)
[error] at com.shepherd.integration.WindowedThresholdSpec.$anonfun$new$4(WindowedThresholdSpec.scala:38)
[error] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Can anyone please help me on this as I'm new also I have see this one java.lang.NoClassDefFoundError: scala/Product$class but this not help me so I have put my problem here.
Try with both the way like uploaded jar directly into the code and pull by S3 but the error is still exists.
resolvers += "Java.net Maven2 Repository" at "https://repo1.maven.org/maven2/"
resolvers += "S3" at "https://s3-eu-west-1.amazonaws.com/com.abc/" -> Test jar file
NOTE:- I have Set the same scala version in my both the application "2.12.6" but issue is still exists.
I'm tring to setup a project with play framework and postgres with slick-codegen. My project is compiling without errors And the Tables class generated is correct. But when I run the project it give me the play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig].
This is the full trace:
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:184)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131)
at scala.Option.map(Option.scala:146)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:131)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129)
at scala.util.Success.flatMap(Try.scala:231)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:129)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:121)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
Caused by: java.lang.NoClassDefFoundError: slick/backend/DatabaseConfig
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)
at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:572)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:558)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:887)
Caused by: java.lang.ClassNotFoundException: slick.backend.DatabaseConfig
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)
I have my project split in 2 subprojects. The Play project and the codegen project that is used to generate the Tables class.
My build.sbt looks like this:
import sbt.Keys._
val slickVersion = "3.2.0"
scalaVersion := "2.11.8"
// The Play project itself
lazy val root = (project in file("."))
.settings(
libraryDependencies ++= List(
"com.netaporter" %% "scala-uri" % "0.4.14",
"net.codingwell" %% "scala-guice" % "4.1.0",
"com.typesafe.play" %% "play-slick" % "2.0.2",
"com.typesafe.play" %% "play-slick-evolutions" % "2.0.2"
)
)
.settings(sharedSettings)
.enablePlugins(Common, PlayScala)
.settings(
name := """Play app"""
)
.dependsOn(codegen)
lazy val codegen = project
.settings(sharedSettings)
.settings(
libraryDependencies ++= List(
"com.typesafe.slick" %% "slick-codegen" % slickVersion
)
)
lazy val sharedSettings = Seq(
scalaVersion := "2.11.8",
scalacOptions := Seq("-feature", "-unchecked", "-deprecation"),
libraryDependencies ++= List(
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2",
"org.slf4j" % "slf4j-api" % "1.7.23",
"org.slf4j" % "log4j-over-slf4j" % "1.7.23", // for any java classes looking for this
"ch.qos.logback" % "logback-classic" % "1.2.1",
"com.typesafe.slick" %% "slick" % slickVersion,
"org.postgresql" % "postgresql" % "9.4.1212",
"com.github.tminglei" %% "slick-pg" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_play-json" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_joda-time" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_jts" % "0.15.0-RC",
"joda-time" % "joda-time" % "2.9.7",
"org.joda" % "joda-convert" % "1.8"
)
)
I also tried removing all the code that use database and the Tables class but i still get this error.
I use a custom postgres driver and it is in the codegen project but is i add the dependsOn(codegen) in the root project, it should not be a problem. Also it is compling without problems with sbt compile.
EDIT:
After some testings, i changed the slick version to 3.1.1 and com.github.tminglei versions to 0.14.3 and it now works for me.
I had the same classapth problem and in the end used the following versions in a play-2.5.x and scala-2.11 project:
libraryDependencies ++= List(
"com.typesafe.play" %% "play-slick" % "2.1.0",
"com.typesafe.play" %% "play-slick-evolutions" % "2.1.0",
"com.typesafe.slick" %% "slick" % "3.2.0",
"com.github.tototoshi" %% "slick-joda-mapper" % "2.3.0"
}
The slick.backend.DatabaseConfig comes from slick-3.1.0 that was needed by play-slick-2.0.2. Since you wanted slick-3.2.0 you need to use play-slick-2.1.0 see https://github.com/playframework/play-slick and https://github.com/tototoshi/slick-joda-mapper .
I'm using this template to develop a microservice:
http://www.typesafe.com/activator/template/activator-service-container-tutorial
My sbt file is like this:
import sbt._
import Keys._
name := "activator-service-container-tutorial"
version := "1.0.1"
scalaVersion := "2.11.6"
crossScalaVersions := Seq("2.10.5", "2.11.6")
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
libraryDependencies ++= {
val containerVersion = "1.0.1"
val configVersion = "1.2.1"
val akkaVersion = "2.3.9"
val liftVersion = "2.6.2"
val sprayVersion = "1.3.3"
Seq(
"com.github.vonnagy" %% "service-container" % containerVersion,
"com.github.vonnagy" %% "service-container-metrics-reporting" % containerVersion,
"com.typesafe" % "config" % configVersion,
"com.typesafe.akka" %% "akka-actor" % akkaVersion exclude ("org.scala-lang" , "scala-library"),
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion exclude ("org.slf4j", "slf4j-api") exclude ("org.scala-lang" , "scala-library"),
"ch.qos.logback" % "logback-classic" % "1.1.3",
"io.spray" %% "spray-can" % sprayVersion,
"io.spray" %% "spray-routing" % sprayVersion,
"net.liftweb" %% "lift-json" % liftVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"io.spray" %% "spray-testkit" % sprayVersion % "test",
"junit" % "junit" % "4.12" % "test",
"org.scalaz.stream" %% "scalaz-stream" % "0.7a" % "test",
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-mock" % "3.5" % "test",
"com.twitter" %% "finagle-http" % "6.25.0",
"com.twitter" %% "bijection-util" % "0.7.2"
)
}
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)
crossPaths := false
parallelExecution in Test := false
assemblyJarName in assembly := "santo.jar"
mainClass in assembly := Some("Service")
The project compiles fine!
But when I run assembly, the terminal show me this:
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /path/.ivy2/cache/io.dropwizard.metrics/metrics-core/bundles/metrics-core-3.1.1.jar:com/codahale/metrics/ConsoleReporter$1.class
[error] /path/.ivy2/cache/com.codahale.metrics/metrics-core/bundles/metrics-core-3.0.1.jar:com/codahale/metrics/ConsoleReporter$1.class
What options do I have to fix it?
Thanks
The issue as it seems transitive dependency of the dependency is resulting with two different versions of metrics-core. The best thing to do would be to used the right library dependency so that you end up with a single version of this library. Please use https://github.com/jrudolph/sbt-dependency-graph , if it is difficult to figure out dependencies.
If it is not possible to get to a single version then you would most likely to go down exclude route . I assume, this only work, if there is compatibility between the all required versions.
I am having an Unexpected exception in my Play2 application with Scala. The same error as mentioned in this question
This is what I get in a browser:
scala.MatchError: java.lang.StackOverflowError (of class
java.lang.StackOverflowError)
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
scala.Option.map(Option.scala:145)
play.PlayReload$.taskFailureHandler(PlayReload.scala:44)
play.PlayReload$.compileFailure(PlayReload.scala:40)
play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
scala.util.Either$LeftProjection.map(Either.scala:377)
play.PlayReload$.compile(PlayReload.scala:17)
My stack traces are very large. A part of them looks as follows:
scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5332)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5279)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5283)
at
scala.tools.nsc.typechecker.Typers$Typer$$anonfun$93.apply(Typers.scala:4440)
[error] (compile:compile) java.lang.StackOverflowError [error]
application -
! Internal server error, for (GET) [/] ->
scala.MatchError: java.lang.StackOverflowError (of class
java.lang.StackOverflowError) at
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
~[na:na] at
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
~[na:na] at scala.Option.map(Option.scala:145)
~[scala-library-2.11.5.jar:na] at
play.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na] at
play.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
I have tried the answers to change the heap and stack size but when I run jconsole it showed that it did not work.
I also tried to change its heap size from this link but it also did not work and I am still getting the same error.
Here is my build.sbt file :
name := """myproject"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
fork in run := true
javaOptions in run ++= Seq(
"-Xms1G", "-Xmx2G", "-XX:MaxPermSize=1024M", "-XX:+UseConcMarkSweepGC")
//SBT_OPTS=-Xss8m
//JAVA_OPTS="-Xms512m "
//val buildSettings = Defaults.defaultSettings ++ Seq( javaOptions += "-Xms1G -Xmx2G"
//)
libraryDependencies ++= Seq("org.scalatest" %% "scalatest" % "2.2.1" % "test"withSources() withJavadoc(),
"com.esotericsoftware.kryo" % "kryo" % "2.10",
"org.mongodb" %% "casbah" % "2.8.0",
"org.slf4j" % "slf4j-api" % "1.6.4",
"org.elasticsearch" % "elasticsearch" % "1.5.0",
"org.scalatest" %% "scalatest" % "2.2.1" % "test"withSources() withJavadoc(),
"org.easymock" % "easymock" % "3.1" withSources() withJavadoc(),
"org.mockito" % "mockito-all" % "1.9.5",
"com.typesafe.akka" %% "akka-actor" % "2.3.6",
"ch.qos.logback" % "logback-core" % "1.0.9",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
Please guide me.
Changing the stack size worked for me
I used this command to run the project
activator run -J-Xss4M -server
I have some code in Scalatra using Atmosphere framework that keeps causing the system to crash after a web request is made. The console shows the data being sent from server to client, but straight after it the following error always appears:
Uncaught error from thread [default-akka.actor.default-dispatcher-11] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[default]
java.lang.NoSuchMethodError: akka.actor.ActorSystem.dispatcher()Lakka/dispatch/MessageDispatcher;
at org.scalatra.atmosphere.package$.jucFuture2akkaFuture(package.scala:29)
at org.scalatra.atmosphere.ScalatraBroadcaster.broadcast(ScalatraBroadcaster.scala:19)
I am using dispatch to make the web requests inside m actors. But I got the same message when I was using spray.
Here is how I make the web request:
Http(Req(_.setUrl(fullUrl))) map {response =>
But the error happens after data has been sent to the client (as you can see the call to "broadcast" in the stack trace. So I don't think it is the web request.
My project build file:
lazy val project = Project (
"",
file("."),
settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ assemblySettings ++ Seq(
organization := Organization,
name := Name,
version := Version,
scalaVersion := ScalaVersion,
resolvers += Classpaths.typesafeReleases,
test in assembly := {},
jarName in assembly := "",
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case PathList(xs) if xs.equals("about.html") => MergeStrategy.first
case x => old(x)
}
},
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test;compile" artifacts (Artifact("javax.servlet", "jar", "jar")),
"org.scalatra" %% "scalatra-atmosphere" % "2.2.1",
"org.scalatra" %% "scalatra-json" % "2.2.1",
"org.json4s" %% "json4s-jackson" % "3.2.4",
"org.eclipse.jetty" % "jetty-websocket" % "8.1.10.v20130312" % "container;compile",
"org.scalatest" % "scalatest_2.10" % "2.0.M6-SNAP17",
"com.typesafe.akka" % "akka-testkit_2.10" % "2.2.0",
"joda-time" % "joda-time" % "2.3",
"com.github.nscala-time" %% "nscala-time" % "0.6.0",
"com.cloudphysics" % "jerkson_2.10" % "0.6.3",
"net.databinder.dispatch" %% "dispatch-core" % "0.11.0"
I looked at the source code of scalatra and it appears that it is code inside the future that is blowing up. I am using the following execution context, which may be relevant:
implicit val ec: ExecutionContext = context.dispatcher
I'm going to take a guess here and say that you are pulling in two versions of the akka-actor jar. You explicitly referencing akka-testkit is going to pull in the akka-actor 2.2.0 jar. I'm guessing that something else (maybe scalatra atmosphere) is also pulling in akka-actor and not the 2.2.0 version. You should check your classpath and see if you indeed to have two versions of akka-actor