1

I'm trying to get smaller scalar executable jar file with sbt-proguard. I added project/plugin.sbt these two lines of code:

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

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

The first one is to get uberjar file, and I could get uberjar with sbt assembly that works fine.

Then, I executed sbt proguard:proguard to get this error message.

[error] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [apple/applescript/AppleScriptEngine.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
java.lang.RuntimeException: Proguard failed with exit code [1]
    at scala.sys.package$.error(package.scala:27)
    ...
    at java.lang.Thread.run(Thread.java:745)
[error] (proguard:proguard) Proguard failed with exit code [1]

From the hint from this post: ProGuard says Unsupported class version number [52.0] (maximum 51.0, Java 1.7) with sbt-proguard, I switched to both Java 1.7 and Java 1.6 with export JAVA_HOME=/usr/libexec/java_home -v '1.6*' command to run proguard to get the slim-lined jar file, but this doesn't run.

Invalid or corrupt jarfile target/scala-2.11/proguard/myproject_2.11-1.0.jar

What might be wrong? These are the lines that are added to build.sbt.

proguardSettings

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

ProguardKeys.options in Proguard += ProguardOptions.keepMain("core.HelloWorld")
Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

1

I believe this is documented in the pro guard docs.

Running your application with java -classpath <jarpath> --class classname <program-arguments> should work.

This happens because pro guard by default removes all MANIFEST files from the jar hence the java runtime cannot find the jar class entries. Another way to do this would be to keep the MANIFEST.md file and run it using the java -jar option but I have never tried that.

Sohaib
  • 4,556
  • 8
  • 40
  • 68
1

Define a recent Proguard version that supports Java 1.8

ProguardKeys.proguardVersion in Proguard := "5.3.3"

Also a couple of useful ones if you run out of mem are

javaOptions in (Proguard, ProguardKeys.proguard) := Seq("-Xmx2G")
javaOptions in (Proguard, ProguardKeys.proguard) += "-Xss1G"