假设Java安装在C:\Program Files\Java,Tomcat安装在:D:\apache-tomcat-6.0.35,要处理的SSH项目部署在D:\apache-tomcat-6.0.35\webapps\MySSHWeb。首先解压ProGuard 4.2,得到其lib目录下的proguardgui.jar、proguard.jar和retrace.jar三个文件;在同一目录下建立脚本文件start.bat,文件内容为:java -Xms512m -Xmx512m -jar proguardgui.jar。运行start.bat打开ProGuard,然后开始设置:
1:在Input/Output页进行设置:
Add input...,输入D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\classes
Add output...,输入D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\classes_ok
Add...,输入D:\apache-tomcat-6.0.35\lib
Add...,输入D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\lib
2: 在Shrinking页进行设置:
取消Applications,选中Library
Add...,Comments为Keep Hibernate PO,Extends/implements class为java.io.Serializable
Add field...,点OK
Add method...,点OK
最后点OK
3: 在Obfuscation页进行设置:
选中Keep attributes
4: 在Information页进行设置:
选中Target,下拉选择1.5
5: 在Process页,点击Process!开始处理
最后可以得到处理后的classes,覆盖到D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\classes下即可。偶尔会出现个别文件有错,可以直接将对应的原文件覆盖过来。最终处理的效果不是很好,有待进一步研究。最终的配置文件如下所示:
-injars 'D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\classes_bak'
-outjars classes_bak_yes
-libraryjars 'C:\Program Files\Java\jre6\lib\rt.jar'
-libraryjars 'D:\apache-tomcat-6.0.35\lib'
-libraryjars 'D:\apache-tomcat-6.0.35\webapps\MySSHWeb\WEB-INF\lib'
-target 1.5
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
# Keep Hibernate PO
-keep class * extends java.io.Serializable {
<fields>;
<methods>;
}
# Keep - Library. Keep all public and protected classes, fields, and methods.
-keep public class * {
public protected <fields>;
public protected <methods>;
}
# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers class * extends java.lang.Enum {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Also keep - Database drivers. Keep all implementations of java.sql.Driver.
-keep class * extends java.sql.Driver
# Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI,
# along with the special 'createUI' method.
-keep class * extends javax.swing.plaf.ComponentUI {
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}
# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}
# Remove - System method calls. Remove all invocations of System
# methods without side effects whose return values are not used.
-assumenosideeffects public class java.lang.System {
public static long currentTimeMillis();
static java.lang.Class getCallerClass();
public static int identityHashCode(java.lang.Object);
public static java.lang.SecurityManager getSecurityManager();