簡體   English   中英

使用Proguard無法將Scala代碼打包到jar文件中

[英]Packaging scala code into a jar file with proguard not working

我有一個這樣的目錄結構:

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")

在我運行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的例子很少。 有人可以幫忙嗎?

您還需要保留main方法作為入口點:

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

ProGuard通常會對此發出警告; 最好不要關閉警告和注釋。

請參閱ProGuard文檔>示例> 典型應用

sbt“ one-jar”是一種與我喜歡的clojure uberjar更接近的解決方案,它更適合我。 可以在這里找到:

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

只需幾行配置,一切都打包好了。 這更接近我的需求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM