如何为netlogo扩展打包akka项目?

tnkciper  于 2022-11-05  发布在  Go
关注(0)|答案(2)|浏览(163)

我尝试做一个简单的基于akka的NetLogo扩展。然而,每当我尝试在NetLogo中加载扩展时,我会得到错误:

Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'

这显然意味着缺少一些配置。然后我继续将reference.conf添加到我的资源文件夹中,但没有运气。
我最后尝试的是使用sbt-assemblty插件,但是我总是得到同样的错误。所以这是我的build。sbt:

name := "TestAkka"

version := "1.0"

scalaVersion := "2.11.7"

scalaSource in Compile <<= baseDirectory(_ / "src")

scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xfatal-warnings",
    "-encoding", "us-ascii")

libraryDependencies ++= Seq(
    "org.nlogo" % "NetLogo" % "5.3.0" from
      "http://ccl.northwestern.edu/devel/NetLogo-5.3-17964bb.jar",
    "asm" % "asm-all" % "3.3.1",
    "org.picocontainer" % "picocontainer" % "2.13.6",
    "com.typesafe" % "config" % "1.3.0",
    "com.typesafe.akka" %% "akka-actor" % "2.4.1",
    "com.typesafe.akka" %% "akka-remote" % "2.4.1"
)

artifactName := { (_, _, _) => "sample-scala.jar" }

packageOptions := Seq(
    Package.ManifestAttributes(
        ("Extension-Name", "sample-scala"),
        ("Class-Manager", "main.scala.akkatest.TestClassManager"),
        ("NetLogo-Extension-API-Version", "5.3")))

packageBin in Compile <<= (packageBin in Compile, baseDirectory, streams) map {
    (jar, base, s) =>

        IO.copyFile(jar, base / "sample-scala.jar")

        Process("pack200 --modification-time=latest --effort=9 --strip-debug " +
          "--no-keep-file-order --unknown-attribute=strip " +
          "sample-scala.jar.pack.gz sample-scala.jar").!!
        if(Process("git diff --quiet --exit-code HEAD").! == 0) {
            Process("git archive -o sample-scala.zip --prefix=sample-scala/ HEAD").!!
            IO.createDirectory(base / "sample-scala")
            IO.copyFile(base / "sample-scala.jar", base / "sample-scala" / "sample-scala.jar")
            IO.copyFile(base / "sample-scala.jar.pack.gz", base / "sample-scala" / "sample-scala.jar.pack.gz")
            Process("zip sample-scala.zip sample-scala/sample-scala.jar sample-scala/sample-scala.jar.pack.gz").!!
            IO.delete(base / "sample-scala")
        }
        else {
            s.log.warn("working tree not clean; no zip archive made")
            IO.delete(base / "sample-scala.zip")
        }
        jar
}

cleanFiles <++= baseDirectory { base =>
    Seq(base / "sample-scala.jar",
        base / "sample-scala.jar.pack.gz",
        base / "sample-scala.zip") }

我有一个项目/程序集.sbt,其内容为:

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

我有一个程序集.sbt,根目录下有以下内容:

import sbtassembly.AssemblyKeys._

baseAssemblySettings

在我的scala代码中,我有:

val configString = ConfigFactory.parseString(
        """
          akka {

            loglevel = "INFO"
            actor {

              provider = "akka.remote.RemoteActorRefProvider"
            }
            remote {

              enabled-transports = ["akka.remote.netty.tcp"]
              netty.tcp {

                hostname = "127.0.0.1"
                port = "9500"
              }

              log-sent-messages = on
              log-received-messages = on
            }
          }
        """.stripMargin)

val config = ConfigFactory.load(configString)

resources文件夹中有一个application.conf文件,我现在不使用它,查看jar tf命令的输出和表达式“reference”,可以清楚地看到reference.conf文件的存在:

我如何将这个akka示例打包为netlogo扩展?
注意:我已经包含了akka-actor和akka-remote作为库依赖项。我在OS X平台上使用Intellij和SBT 0.13.8。
编辑:在接受了Ayush的建议后,我从命令sbt汇编中得到了以下输出,但仍然存在相同的异常:

ubbxdtey

ubbxdtey1#

我认为问题是在使用sbt:assembly时,默认的合并策略排除了所有的reference.conf文件。这是我在文档中发现的。
如果多个文件共享相同的相对路径(例如,多个依赖关系JAR中名为application.conf的资源),则默认策略是验证所有候选文件是否具有相同的内容,否则将出错。
是否可以尝试按如下方式添加合并策略

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

iyzzxitl2#

有一个额外的技巧来解决这个问题,新的akka库,因为akka不包括他们的所有默认配置在resource.conf
https://stackoverflow.com/a/72325132/1286583

相关问题