2

我已经设置了一个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
)
4

2 回答 2

2

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

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

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

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

于 2014-12-16T18:37:44.997 回答
2

这是因为您缺少其他依赖的临时依赖akka-persistence项。例如,默认情况下它取决于:

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

所有这些都有进一步的依赖关系。而不是手动下载/添加 jars,您应该添加akka-persistencelibraryDependencies您的build.sbt其中,这将自动提取所有必需的依赖项。

libraryDependencies += "com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.4"
于 2014-12-17T11:42:10.023 回答