无法组装Scala / akka项目

时间:2018-06-20 10:34:38

标签: scala sbt akka akka-stream

我是sbt和scala的新人。只是想让jar文件在服务器上运行,但是当我尝试编译jar文件时出现错误。程序代码非常简单,只有一个类(不能在此处发布,stackoverflow不允许)。当我在Intellij中运行它时,一切都很好。但是sbt程序集会引发此错误:

NSPhotoLibraryAddUsageDescription

built.sbt

[info] Merging files...
[error] scala.MatchError: akka\stream\OverflowStrategies$.class (of class java.lang.String)
[error]         at $a019333dc409d47a4d92$.$anonfun$$sbtdef$2(D:\workspace_scala\TestSbt2\build.sbt:25)
[error]         at sbtassembly.Assembly$.$anonfun$applyStrategies$6(Assembly.scala:115)
[error]         at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
[error]         at scala.collection.Iterator.foreach(Iterator.scala:929)
[error]         at scala.collection.Iterator.foreach$(Iterator.scala:929)
[error]         at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
[error]         at scala.collection.IterableLike.foreach(IterableLike.scala:71)
[error]         at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
[error]         at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:234)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
[error]         at scala.collection.AbstractTraversable.map(Traversable.scala:104)
[error]         at sbtassembly.Assembly$.applyStrategies(Assembly.scala:114)
[error]         at sbtassembly.Assembly$.x$1$lzycompute$1(Assembly.scala:26)
[error]         at sbtassembly.Assembly$.x$1$1(Assembly.scala:24)
[error]         at sbtassembly.Assembly$.stratMapping$lzycompute$1(Assembly.scala:24)
[error]         at sbtassembly.Assembly$.stratMapping$1(Assembly.scala:24)
[error]         at sbtassembly.Assembly$.inputs$lzycompute$1(Assembly.scala:68)
[error]         at sbtassembly.Assembly$.inputs$1(Assembly.scala:58)
[error]         at sbtassembly.Assembly$.apply(Assembly.scala:85)
[error]         at sbtassembly.Assembly$.$anonfun$assemblyTask$1(Assembly.scala:249)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error]         at java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error]         at java.lang.Thread.run(Unknown Source)
[error] (assembly) scala.MatchError: akka\stream\OverflowStrategies$.class (of class java.lang.String)
[error] Total time: 1 s, completed Jun 20, 2018 1:20:02 PM

project / assembly.sbt

name := "TestSbt2"
version := "0.1"
scalaVersion := "2.12.4"

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.13"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.13"
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.1.0"

assemblyMergeStrategy in assembly := {
  case PathList("reference.conf") => MergeStrategy.concat
}

程序代码:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

3 个答案:

答案 0 :(得分:0)

不确定是怎么回事,但是如果在default定义中添加assemblyMergeStrategy大小写,它应该可以正常工作。

例如:

assemblyMergeStrategy in assembly := {
  case "reference.conf" => MergeStrategy.concat
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

小修改:

实际上在回购协议上说

assemblyMergeStrategy in assembly expects a function. You can't do assemblyMergeStrategy in assembly := MergeStrategy.first

答案 1 :(得分:0)

它显示为“ MatchError”的事实,可以在build.sbt文件中找到,而您的sbt文件显示为

assemblyMergeStrategy in assembly := {
  case PathList("reference.conf") => MergeStrategy.concat
}

告诉我,您想使用备用案例。

在相同的匹配项中(在您的case PathList之后)将其添加为第二种情况

case x =>
  val oldStrategy = (assemblyMergeStrategy in assembly).value
  oldStrategy(x)

(从GitHub-sbt-assembly复制)

答案 2 :(得分:0)

谢谢大家!

这有助于:

mainClass in assembly := Some("chat.Server2")

assemblyMergeStrategy in assembly := {
  case "reference.conf" => MergeStrategy.concat
  case x =>
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}