(だいぶ前に書いた記事で、公開にあたって再検証してないので、間違いがあったらごめんなさい。)
ref: http://d.hatena.ne.jp/h_sakurai/20081213#p1
flagir を作るときに参考にさせてもらったのですが、ProGuard のところで躓きました。
$ java -jar proguard.jar -injars app.jar:/home/mame/local/scala-2.7.4.final/lib/scala-library.jar -outjars app2.jar -libraryjars /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -keep public class app -dontusemixedcaseclassnames -dontoptimize ProGuard, version 4.3 Reading program jar [/home/mame/work/app/app.jar] Reading program jar [/home/mame/local/scala-2.7.4.final/lib/scala-library.jar] Reading library jar [/usr/lib/jvm/java-1.5.0-sun-1.5.0.14/jre/lib/rt.jar] Note: scala.xml.include.sax.Main$ calls '(org.xml.sax.EntityResolver)Class.forName(variable).newInstance()' Warning: scala.util.parsing.combinator.Parsers$$anonfun$repsep$1: can't find referenced class scala.Nothing Warning: scala.collection.jcl.Buffer$DefaultBufferIterator: can't find referenced class scala.collection.jcl.Buffer$DefaultSeqIterator Warning: scala.actors.Actor: can't find referenced class scala.Nothing Warning: scala.actors.Actor: can't find referenced class scala.Nothing Warning: scala.collection.jcl.MutableSeq$Projection$$anon$1: can't find referenced class scala.collection.jcl.MutableSeq$Projection$Filter Warning: scala.collection.immutable.Map$$anon$1: can't find referenced class scala.Nothing (snip) Warning: scala.Stream$$anon$1: can't find referenced class scala.Nothing Warning: scala.Stream$$anon$1: can't find referenced class scala.Nothing Warning: scala.Stream$$anon$1: can't find referenced class scala.Nothing Warning: scala.util.parsing.combinatorold.lexical.StdLexical$$anonfun$whitespace$1$$anonfun$apply$26: can't find referenced class scala.Nothing Note: there were 1 class casts of dynamically created class instances. You might consider explicitly keeping the mentioned classes and/or their implementations (using '-keep'). Warning: there were 109 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile them and try again. Alternatively, you may have to specify the options '-dontskipnonpubliclibraryclasses' and/or '-dontskipnonpubliclibraryclassmembers'. Error: Please correct the above warnings first.
scala.Nothing クラスなどが参照されてるけど見つからんとのこと。実際、scala-library.jar に scala/Nothing.class は入っていない。Nothing クラスは型として参照されることはあっても、インスタンス化されたりメソッド呼び出しされたりすることがないので、無くても困らないんだろう。 ProGuard を使うときとか Java との連携とかで困っているぽい事例はちらほら見つかる (Distributing an application written in Scala からいくつかリンク) 。そのうち直るのかな?
要するに、無くてもいいクラスが見つからないといって ProGuard が怒っているという話。上のリンク先では scala.Nothing の入った jar を作って libraryjars に渡して回避してるみたいだけど、Nothing のほかにも見つからないクラスがあるみたいで、ちょっとめんどい。
それでどうしたかというと、ProGuard に -dontwarn というオプションを見つけた。
-dontwarn
ProGuard Usage
Specifies not to warn about unresolved references and other important problems at all. Ignoring warnings can be dangerous. For instance, if the unresolved classes or class members are indeed required for processing, the processed code will not function properly. Only use this option if you know what you're doing!
あんまり使いたくないオプションだけど、まあ一応これで動いた。
$ java -jar proguard.jar -injars app.jar:/home/mame/local/scala-2.7.4.final/lib/scala-library.jar -outjars app2.jar -libraryjars /usr/lib/jvm/java-1.5.0-sun/jre/lib/rt.jar -keep public class app -dontusemixedcaseclassnames -dontoptimize -dontwarn ProGuard, version 4.3 Reading program jar [/home/mame/work/app/app.jar] Reading program jar [/home/mame/local/scala-2.7.4.final/lib/scala-library.jar] Reading library jar [/usr/lib/jvm/java-1.5.0-sun-1.5.0.14/jre/lib/rt.jar] Note: scala.xml.include.sax.Main$ calls '(org.xml.sax.EntityResolver)Class.forName(variable).newInstance()' Note: there were 1 class casts of dynamically created class instances. You might consider explicitly keeping the mentioned classes and/or their implementations (using '-keep'). Preparing output jar [/home/mame/work/app/app2.jar] Copying resources from program jar [/home/mame/work/app/app.jar] Copying resources from program jar [/home/mame/local/scala-2.7.4.final/lib/scala-library.jar] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [scala-library.jar:META-INF/MANIFEST.MF]) Warning: can't write resource [library.properties] (Duplicate zip entry [scala-library.jar:library.properties])