Akka无法启动ActorSystem

时间:2016-11-02 16:22:14

标签: scala akka

我一直关注QuickStart guide for Akka Streams,而我遇到了错误。我的代码很简单:

object Main extends App {
  implicit val system = ActorSystem("QuickStart")
  implicit val materializer = ActorMaterializer()

  val source: Source[Int, NotUsed] = Source(1 to 100)
  source.runForeach(i => println(i)) (materializer)
}

然而,这会导致错误:

  

线程中的异常" main" java.lang.NoClassDefFoundError:scala / Product $ class       at akka.util.Timeout。(Timeout.scala:13)       at akka.actor.ActorSystem $ Settings。(ActorSystem.scala:179)       at akka.actor.ActorSystemImpl。(ActorSystem.scala:530)       at akka.actor.ActorSystem $ .apply(ActorSystem.scala:142)       at akka.actor.ActorSystem $ .apply(ActorSystem.scala:109)       at streams_test.Main $ .delayedEndpoint $ streams_test $ Main $ 1(Main.scala:14)       在streams_test.Main $ delayedInit $ body.apply(Main.scala:13)       在scala.runtime.AbstractFunction0.apply $ mcV $ sp(AbstractFunction0.scala:12)       在scala.App。$ anonfun $ main $ 1 $ adapt(App.scala:76)       在scala.collection.immutable.List.foreach(List.scala:378)       在scala.App.main(App.scala:76)       在scala.App.main $(App.scala:74)       at streams_test.Main $ .main(Main.scala:13)       在streams_test.Main.main(Main.scala)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)   引起:java.lang.ClassNotFoundException:scala.Product $ class       at java.net.URLClassLoader.findClass(URLClassLoader.java:381)       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)       at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)       ......还有19个

我也试过在没有运气的情况下通过sbt控制台运行它。有谁知道造成这个问题的原因是什么?它正在被抛弃:

implicit val system = ActorSystem("QuickStart")

根据要求,我的build.sbt文件:

name := "Akka_test"

version := "1.0"

scalaVersion := "2.12.0"

// https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor_2.11
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.11" % "2.3.9"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-stream_2.11
libraryDependencies += "com.typesafe.akka" % "akka-stream_2.11" % "2.4.12"
// https://mvnrepository.com/artifact/org.twitter4j/twitter4j-core
libraryDependencies += "org.twitter4j" % "twitter4j-core" % "4.0.2"

1 个答案:

答案 0 :(得分:9)

这可能是您可能使用2.11编译库和2.11编译器的Scala版本问题,反之亦然。

如果在build.sbt中明确包含scala版本并在build.sbt中的groupId之后使用%%,则可以避免遇到此问题

使用此

scalaVersion := "scala_version"

libraryDependencies += "group_id" %% "artificat_id" % "version"

而不是

libraryDependencies += "group_id" % "artificat_id_scala_version" % "version"