使用Play Framework进行akka-persistence

时间:2014-12-16 18:07:33

标签: java playframework sbt akka akka-persistence

我已经设置了Play Framework项目,我想要使用akka-persistence。我下载了用于akka-persistence的JAR并将其放在我的Play项目的lib文件夹中。 akka-persistence类是可识别的,我可以编译并运行应用程序,但是一旦应用程序启动,它就会抛出NoClassDefFoundError异常并且应用程序停止。我之前已成功使用过akka-persistence(尽管没有使用Play Framework项目)。任何提示?

备注:我使用Play Framework 2.3.4(我相信使用Akka 2.3.4,手动删除了akka-persistence模块)。我四处使用Java(不是Scala)。 akka-persistence的jar是akka-persistence-experimental_2.11-2.3.4.jar。抛出的异常和堆栈跟踪如下:

[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

我的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
)

2 个答案:

答案 0 :(得分:2)

好吧,我发现当前的解决方案是将这两个依赖项添加到build.sbt:

  "org.iq80.leveldb" % "leveldb" % "0.7"

  "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8"

尽管如此,我很高兴听到为什么这样的事情能够解决这个问题,以及它是否在网络上的某个地方得到了很好的记录。

答案 1 :(得分:2)

这是因为您错过了akka-persistence依赖的其他瞬态依赖项。例如,默认情况下,它取决于:

  • org.fusesource.leveldbjni:leveldbjni-all:1.7
  • org.iq80.leveldb:leveldb:0.5
  • com.google.protobuf:protobuf-java:2.5.0

所有这些都有进一步的依赖性。您不应手动下载/添加jar,而应在akka-persistence中将libraryDependencies添加到build.sbt,这将自动提取其所有必需的依赖项。

libraryDependencies += "com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.4"