2016-09-30 32 views
0

我想打包一个非托管jar以及一些Scala代码。我使用IntelliJ编程,我不确定包是否正确构建。这是build.sbt包装好吗?

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将被转换为.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

你不说你是如何构建它,所以这可能是第一个问题。具体而言,您应该使用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

+0

我不希望jar有一个主要方法,我希望它是一个lib,就是这样。通过提取生成的jar的内容,似乎所有的依赖关系都被添加了。那么问题依然是为什么ikvmc无法将其转换为dll。谢谢,至少看起来我的感觉没问题。 :) – Marin

+0

@Marin乐于帮忙!请记住点赞和/或接受帮助您找到解决方案的答案,或阐明这种情况。通过这样做,人们将来会更有可能帮助你!我还会更新您的原始文章,并提供您收到的警告,因为它可能会提供更多线索,让我们为您提供帮助。 –