我需要创建一个Nutch插件,它使用Akka与一些外部应用程序通信。为了做到这一点,我需要将插件打包为胖罐 - 我使用sbt-assembly版本0.8.3。
当我尝试运行插件时,我得到了异常
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'
好像Akka无法找到reference.conf
。这很奇怪,因为sbt-assembly
should be able正确打包该文件,实际上我可以在创建的jar中看到它的内容。
我的build.sbt
看起来像这样:
import AssemblyKeys._
name := "my-project"
version := "0.1-SNAPSHOT"
scalaVersion := "2.10.0"
resolvers ++= Seq(
"Central Repo" at "http://repo1.maven.org/maven2",
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Akka io" at "http://akka.io/repository"
)
libraryDependencies ++= Seq(
...,
"com.typesafe.akka" %% "akka-actor" % "2.1.1",
"com.typesafe.akka" %% "akka-remote" % "2.1.1"
)
seq(assemblySettings: _*)
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case "plugin.xml" =>
MergeStrategy.first
case x if x startsWith "org/apache/jasper" =>
MergeStrategy.last
case x if x startsWith "javax/xml" =>
MergeStrategy.last
case x if x startsWith "javax/servlet" =>
MergeStrategy.last
case x if x startsWith "org/apache/commons" =>
MergeStrategy.last
case x if x startsWith "org/apache/xmlcommons" =>
MergeStrategy.last
case x if x startsWith "org/xml/sax" =>
MergeStrategy.last
case x if x startsWith "org/w3c/dom" =>
MergeStrategy.last
case x => old(x)
}
}
需要最后一行来修复nutch和hadoop之间的一些冲突。
打包Akka应用程序的正确方法是什么?
答案 0 :(得分:3)
截至2013年11月,sbt-assembly的最新版本为0.10.1,对于sbt 0.13。 使用这个,我能够使用默认的合并策略使用最新的稳定Akka 2.2.3创建一个胖罐。
项目/ build.properties:
sbt.version=0.13.0
项目/ assembly.sbt:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.10.1")
assembly.sbt:
import AssemblyKeys._
assemblySettings
build.sbt:
name := "sbt-assembly-akka-sample"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.10.3"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.2.3",
"com.typesafe.akka" %% "akka-remote" % "2.2.3"
)
的src /主/阶/ actor.scala:
package hello
import akka.actor.{Actor, Props}
import akka.event.Logging
class MyActor extends Actor {
val log = Logging(context.system, this)
def receive = {
case "test" ⇒ log.info("received test")
case _ ⇒ log.info("received unknown message")
}
}
的src /主/阶/ app.scala:
package hello
object Main extends App {
import akka.actor.{ActorSystem, Props}
val system = ActorSystem("mySystem")
val myActor = system.actorOf(Props[MyActor], "myactor")
myActor ! "test"
}
这是我通过运行assembly
得到的:
> assembly
[info] Updating {file:/xxx/sbt-assembly-01/}sbt-assembly-01...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Scala sources to /xxx/sbt-assembly-01/target/scala-2.10/classes...
[info] Including: uncommons-maths-1.2.2a.jar
[info] Including: protobuf-java-2.4.1.jar
[info] Including: config-1.0.2.jar
[info] Including: netty-3.6.6.Final.jar
[info] Including: akka-remote_2.10-2.2.3.jar
[info] Including: akka-actor_2.10-2.2.3.jar
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for test:test
[info] Including: scala-library-2.10.3.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/NOTICE.txt' with strategy 'rename'
[warn] Merging 'META-INF/license' with strategy 'rename'
[warn] Merging 'META-INF/LICENSE.txt' with strategy 'rename'
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'reference.conf' with strategy 'concat'
[warn] Strategy 'concat' was applied to a file
[warn] Strategy 'discard' was applied to a file
[warn] Strategy 'rename' was applied to 3 files
[info] SHA-1: 1e9dcebeddc8e2a7d41a0c55a663f9ca0000000
[info] Packaging /xxx/sbt-assembly-01/target/scala-2.10/sbt-assembly-akka-sample-assembly-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 13 s, completed Nov 11, 2013 8:57:18 PM
这就是运行jar的样子:
$ java -jar target/scala-2.10/sbt-assembly-akka-sample-assembly-0.1.0-SNAPSHOT.jar
[INFO] [11/11/2013 20:59:48.265] [mySystem-akka.actor.default-dispatcher-2] [akka://mySystem/user/myactor] received test