Reputation: 6242
I have setup a Play Framework project and I want to use akka-persistence along with it. I downloaded the JAR for akka-persistence and dropped it on the lib folder of my Play project. The akka-persistence classes are recognized and I can compile and run the application, but as soon as the application starts, it throws a NoClassDefFoundError
exception and the application stops. I have successfully used akka-persistence before (although not with Play Framework project). Any hints?
Notes: I'm using Play Framework 2.3.4 (which I believe uses Akka 2.3.4, with the akka-persistence module manually removed). I'm using Java all around (not Scala). The jar for akka-persistence is akka-persistence-experimental_2.11-2.3.4.jar. The exception thrown and the stack trace is the following:
[info] play - Application started (Dev)
[info] play - Starting application default Akka system.
Uncaught error from thread [application-akka.persistence.dispatchers.default-plugin-dispatcher-7] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoClassDefFoundError: org/iq80/leveldb/DBFactory
at akka.persistence.journal.leveldb.LeveldbJournal.<init>(LeveldbJournal.scala:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:379)
at akka.util.Reflect$.instantiate(Reflect.scala:45)
at akka.actor.NoArgsReflectConstructor.produce(Props.scala:361)
at akka.actor.Props.newActor(Props.scala:252)
at akka.actor.ActorCell.newActor(ActorCell.scala:552)
at akka.actor.ActorCell.create(ActorCell.scala:578)
at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:456)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:478)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:263)
at akka.dispatch.Mailbox.run(Mailbox.scala:219)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.iq80.leveldb.DBFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
[ERROR] [12/16/2014 20:56:12.495] [application-akka.persistence.dispatchers.default-plugin-dispatcher-7] [ActorSystem(application)] Uncaught error from thread [application-akka.persistence.dispatchers.default-plugin-dispatcher-7] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
java.lang.NoClassDefFoundError: org/iq80/leveldb/DBFactory
at akka.persistence.journal.leveldb.LeveldbJournal.<init>(LeveldbJournal.scala:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:379)
at akka.util.Reflect$.instantiate(Reflect.scala:45)
at akka.actor.NoArgsReflectConstructor.produce(Props.scala:361)
at akka.actor.Props.newActor(Props.scala:252)
at akka.actor.ActorCell.newActor(ActorCell.scala:552)
at akka.actor.ActorCell.create(ActorCell.scala:578)
at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:456)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:478)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:263)
at akka.dispatch.Mailbox.run(Mailbox.scala:219)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.iq80.leveldb.DBFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
My build.sbt:
name := """project-name"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.4",
"org.iq80.leveldb" % "leveldb" % "0.7", // I added this
"org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8", // and this, because of the jar
"org.scalatest" %% "scalatest" % "2.1.6" % "test",
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.9.5"
)
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs
)
Upvotes: 2
Views: 2308
Reputation: 7174
This is because you're missing other transient dependencies that akka-persistence
depends on. For example by default it depends on:
org.fusesource.leveldbjni:leveldbjni-all:1.7
org.iq80.leveldb:leveldb:0.5
com.google.protobuf:protobuf-java:2.5.0
And all these have further dependencies. Instead of downloading/adding jars manually you should add akka-persistence
to libraryDependencies
in your build.sbt
which will automatically pull in all it's requisite dependencies.
libraryDependencies += "com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.4"
Upvotes: 2
Reputation: 6242
Well, the current solution I found is adding this two dependencies to build.sbt:
"org.iq80.leveldb" % "leveldb" % "0.7"
"org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8"
Nonetheless, I would be very happy to hear why such thing solves the issue and if it's well documented somewhere around the web.
Upvotes: 2