【发布时间】:2018-01-21 12:05:35
【问题描述】:
View repository at this specific commit here
我正在组建一个小型 SBT 项目并学习如何使用 akka 演员。我能够得到一个只使用 akka 的简单示例,但是一旦我使用外部库,事情就会停止工作。我得到了一个非常大的堆栈跟踪
objc[15196]: Class JavaLaunchHelper is implemented in both
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java (0x10cc6c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ccf84e0). One of the two will be used. Which one is undefined.
Detected java.lang.NoSuchMethodError error, which MAY be caused by incompatible Akka versions on the classpath. Please note that a given Akka version MUST be the same across all modules of Akka that you are using, e.g. if you use akka-actor [2.5.8 (resolved from current classpath)] all other core Akka modules MUST be of the same version. External projects like Alpakka, Persistence plugins or Akka HTTP etc. have their own version numbers - please make sure you're using a compatible set of libraries.
Uncaught error from thread [HelloSystem-akka.actor.default-dispatcher-4]: akka.actor.ActorCell.addFunctionRef(Lscala/Function2;)Lakka/actor/FunctionRef;, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for for ActorSystem[HelloSystem]
java.lang.NoSuchMethodError: akka.actor.ActorCell.addFunctionRef(Lscala/Function2;)Lakka/actor/FunctionRef;
我的依赖项如下所示:
object v {
val akka = "2.5.8"
val scrape = "0.4.0"
}
val akka = Seq(
"com.typesafe.akka" %% "akka-actor" % v.akka,
"com.typesafe.akka" %% "akka-slf4j" % v.akka
)
val scrape = Seq(
"io.bfil" %% "scalescrape" % v.scrape
)
lazy val allDeps = akka ++ scrape
我正在使用this library,它也使用akka 版本5.8,那么给出了什么?这个冲突版本的 akka actor 是从哪里来的?这是我的build.sbt,其中包括我尝试使用的冲突管理器:
import Dependencies._
name := "sputnik-scraper"
version := "0.1"
scalaVersion := "2.12.4"
conflictManager := ConflictManager.strict
dependencyOverrides += "com.typesafe.akka" %% "akka-actor" % "2.5.8"
lazy val root = (project in file(".")).settings(
libraryDependencies ++= allDeps
)
编辑:从 main 添加代码。
import akka.actor.{ActorSystem, Props}
import io.bfil.scalescrape.actor.ScrapingActor
object Main extends App {
val system = ActorSystem("HelloSystem")
// default Actor constructor
val helloActor = system.actorOf(Props[ExampleScraper], name = "helloactor")
helloActor ! "hello"
helloActor ! "buenos dias"
}
class ExampleScraper extends ScrapingActor {
private val baseUrl = "https://www.sputnikmusic.com/"
override def receive: Receive = {
case _ => grabMainTitle(baseUrl)
}
private def grabMainTitle(url: String) =
scrape {
get(url) { response =>
complete(doIt(response))
}
}
private def doIt(response: Any): Unit = {
println(response)
}
}
【问题讨论】:
-
如果可能的话,你能在这里提供演员和主程序
-
我将代码添加到我的原始帖子中。