这个build.sbt包装好吗?

时间:2016-09-30 18:32:43

标签: scala jar sbt

我正在尝试打包一个非托管jar以及一些Scala代码。我使用IntelliJ编程,我不确定是否正确构建了包。

我的build.sbt如下:

name := "InvokeCompiler"

version := "1.0"

scalaVersion := "2.11.8"

exportJars := true

val parserLocation = "lib/parser-0.0.1.jar"

mappings in (Compile, packageBin) ~= {

    _.filter(!_._1.getName.startsWith("Main"))
}

//unmanagedJars in Compile += file(parserLocation)

mappings in (Compile, packageBin) <+= baseDirectory map { base =>

    (base / parserLocation) -> "parser-0.0.1.jar"
}

我想创建一个包含非托管jar和我编写的代码的新jar文件。此jar将转换为.dll以便在C#中使用它。但是,当这样做时,IKVMC会抛出各种警告。当我添加它产生的.dll时,.dll只包含我自己编写的类。

修改: 在阅读了福特先生的评论之后,以下是我在生成的jar上运行ikvmc时得到的警告和错误:

PROMPT:> ikvmc -target:library compiled.jar
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/

note IKVMC0002: Output file is "compiled.dll"
warning IKVMC0100: Class "org.nlogo.core.FrontEndInterface" not found
warning IKVMC0100: Class "scala.Tuple2" not found
warning IKVMC0100: Class "scala.reflect.ScalaSignature" not found
warning IKVMC0100: Class "scala.Option" not found
warning IKVMC0100: Class "org.nlogo.core.Program" not found
warning IKVMC0100: Class "scala.collection.immutable.ListMap" not found
warning IKVMC0100: Class "org.nlogo.core.ExtensionManager" not found
warning IKVMC0100: Class "org.nlogo.core.CompilationEnvironment" not found
warning IKVMC0100: Class "org.nlogo.core.Femto$" not found
warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in "Interface.ASTSingleton$.getFrontEndCompiledAsJSON(Ljava.lang.String;)Lscala.Tuple2;"
    ("org.nlogo.core.FrontEndInterface")
warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in "Interface.ASTSingleton$.getFrontEndSingletion()Lorg.nlogo.core.FrontEndInterface;"
    ("org.nlogo.core.Femto$")

1 个答案:

答案 0 :(得分:1)

你不会说你是如何构建它的,所以这可能是第一个问题。具体来说,您应该使用sbt publish-local命令。要验证依赖项是否包含,只需解压缩JAR文件并查看。

如果您需要生成的JAR文件可执行,那么您应该将其添加到build.sbt

mainClass in Compile := Some("name.of.your.main.Class")

name.of.your.main.Class替换为您的班级名称。你正在做类似但可能有问题的事情:

mappings in (Compile, packageBin) ~= {
    _.filter(!_._1.getName.startsWith("Main"))
}

这意味着任何具有不以Main开头的类名的内容都将被过滤掉。除非你有充分的理由,否则我将摆脱它并明确指出包主方法。 mappings的作用是described here