Reputation: 10768
I have a java application using the pdfbox library, which makes 10mb. I use just a few classes of this library.
I thought that ProGuard would generate a standalone jar for my application. But the jar generated by ProGuard still needs the pdfbox.jar in the /lib folder to run. Am I doing something wrong? How could I achieve my goal? (leaving out the 99% of the library classes I don't use).
Note after comments: - the original jar and its libraries are generated with Netbeans. I first used ProGuard GUI but following the comments I received on this question, I switched to scripting. Same result: the app works only when the libraries are in a /lib folder next to the jar.
The Proguard script:
-injars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\ZoText.jar"
-outjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\ZoText_short.jar"
-libraryjars <java.home>/lib/rt.jar
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\Boilerpipe_short.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\commons-io-2.1.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\commons-lang3-3.0.1.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\guava-10.0.1.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\nekohtml.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\pdfbox-app-1.6.0.jar"
-libraryjars "C:\Users\C. Levallois\Documents\NetBeansProjects\ZoText\dist\lib\xercesImpl.jar"
-printmapping proguard.map
-keep public class proguard.ProGuard {
public static void main(java.lang.String[]);
}
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * {
public protected *;
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
Upvotes: 2
Views: 2435
Reputation: 3244
Though it's too late for you, here is the tool doing exactly you wanted:
The tool minimize-jar removes unused classes and creates a uber jar based on verbose:class
information. It's only 5KB and has no dependency.
Upvotes: 1
Reputation: 66866
The -libraryjars
hold code that is assumed to be available to your optimized app at runtime. That is, Proguard does not include them in its output; it merely needs them for reference as it is processing the code in -injars
.
Take away Proguard for a moment: your original unoptimized JAR doesn't work without this library class either, right? Proguard doesn't change that.
If you want it to be packaged up together in the optimized output it has to be present in the input. You would have to include these extra jars as -injars
, or JARred up together with the input in the first place in order for them to appear in the output.
But, yes: Proguard can strip out unused classes, including those that you built in from this other library, if you configure it to.
Upvotes: 2
Reputation: 718688
According to my reading of the manual, ProGuard does leave out unused classes for the JAR files that it process. So I suspect that you are not processing the pdfbox.jar
file; i.e. you just have it on the classpath.
I recommend that you run Proguard from a script rather than the GUI. This will allow you to incorporate the obfuscation step into your main build scripts, version control the scripts and ... show other people the script to get their advice / help.
Upvotes: 1