【问题标题】:Packaging scala code into a jar file with proguard not working将scala代码打包到一个jar文件中,proguard不起作用
【发布时间】:2014-02-23 01:35:07
【问题描述】:

我有一个这样的目录结构:

CSV_generator
  src
   main
    scala
     CSVGenerator.scala
  project
   plugins.sbt

我的 scala 对象的内容是这样的:

package tools.csv_generator

object CSV_Generator{
 import java.nio.file.{Paths, Files}
 import java.io.File
 import org.rogach.scallop._

def main(args: Array[String]){
  val opts = new ScallopConf(args) {

  banner("""This is the program CSV Generator""")
  val file_path = opt[String]("file_path",
                              required = true,
                              descr = "File Path")
  val dome_string = opt[String]("dome_string",
                                required = true,
                                descr = "Dome String")
  }

我的 csv_generator/project/plugins.sbt:

  addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")

我的 csv_generator/build.sbt 是:

  proguardSettings

  ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings"
                                     , "-keepclasseswithmembers  class                    scala.CSV_Generator")

  ProguardKeys.options in Proguard +=         ProguardOptions.keepMain("src.main.scala.CSV_Generator")

在我的 sbt 中,当我运行 proguard:proguard 试图将我的所有代码打包到一个可运行的独立 jar 文件中时,我得到了这个:

  [error] Error: The output jar is empty. Did you specify the proper '-keep' options?
  [trace] Stack trace suppressed: run last proguard:proguard for the full output.
  [error] (proguard:proguard) Proguard failed with exit code [1]
  [error] Total time: 14 s, completed Jan 31, 2014 12:18:38 AM

对于像我这样的小应用程序,proguard 的示例很少。有人可以帮忙吗?

【问题讨论】:

  • 您的目录结构在帖子中并不真正可见。

标签: scala proguard xsbt-proguard-plugin


【解决方案1】:

你还需要将main方法作为入口点:

-keep class scala.CSV_Generator {
    public static void main(java.lang.String[]);
}

ProGuard 通常会对此发出警告;最好不要关闭警告和注释。

请参阅 ProGuard 文档 > 示例 > A typical application

【讨论】:

  • 感谢您的指点。我添加了这个,但现在问题似乎是proguard似乎永远运行,进程似乎没有结束。
【解决方案2】:

一个不太强大的解决方案是 sbt “one-jar”,它更接近于 clojure 的 uberjar,我发现它非常适合我。可以在这里找到:

https://github.com/retronym/sbt-onejar

使用几行配置,一切都打包好了。这更接近我的需要。

【讨论】:

    猜你喜欢
    • 2017-01-11
    • 2014-09-10
    • 2015-08-16
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多