Proguard可以忽略库中未使用的类吗? [英] Can proguard leave out the unused classes of the libraries?
问题描述
我有一个使用pdfbox库的Java应用程序,其大小为10mb.我只使用了该库的几个类.
I have a java application using the pdfbox library, which makes 10mb. I use just a few classes of this library.
我认为ProGuard会为我的应用程序生成一个独立的jar.但是ProGuard生成的jar仍需要/lib文件夹中的pdfbox.jar才能运行.难道我做错了什么?我如何实现我的目标? (省去了我不使用的99%的库类).
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).
评论后请注意: -原始的jar及其库是使用Netbeans生成的.我最初使用ProGuard GUI,但是在收到有关此问题的评论后,我转向了脚本编写.结果相同:仅当库位于jar旁边的/lib文件夹中时,该应用程序才能工作.
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.
Proguard脚本:
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();
}
推荐答案
尽管对您来说太迟了,但以下工具正是您想要的:
Though it's too late for you, here is the tool doing exactly you wanted:
该工具 minimize-jar 会删除未使用的类并根据verbose:class
信息创建一个uber jar.它只有5KB,没有依赖性.
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.
这篇关于Proguard可以忽略库中未使用的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!