使用Proguard做Java代码混淆
下载Proguard, 我下的是最新的Proguad5.2
在windows下运行bin/proguardgui.bat, 可以看见图形界面, 载入配置, 然后process.
配置文件例子
1 -injars 'C:\Users\MicrosoftUser\Desktop\demo.jar' 2 -outjars 'C:\Users\MicrosoftUser\Desktop\demo-pg.jar' 3 4 -libraryjars 'D:\workJava\workspace\demo\lib\Memcached-Java-Client-3.0.2.jar' 5 -libraryjars 'D:\workJava\workspace\demo\lib\commons-codec-1.6.jar' 6 -libraryjars 'D:\workJava\workspace\demo\lib\commons-imaging-1.0-SNAPSHOT.jar' 7 -libraryjars 'D:\workJava\workspace\demo\lib\commons-io-2.2.jar' 8 -libraryjars 'D:\workJava\workspace\demo\lib\commons-lang3-3.1.jar' 9 -libraryjars 'D:\workJava\workspace\demo\lib\dom4j-1.6.1.jar' 10 -libraryjars 'D:\workJava\workspace\demo\lib\ehcache-core-2.6.9.jar' 11 -libraryjars 'D:\workJava\workspace\demo\lib\httpclient-4.3.3.jar' 12 -libraryjars 'D:\workJava\workspace\demo\lib\httpcore-4.3.2.jar' 13 -libraryjars 'D:\workJava\workspace\demo\lib\im4java-1.4.0.jar' 14 -libraryjars 'D:\workJava\workspace\demo\lib\jackson-core-asl-1.9.13.jar' 15 -libraryjars 'D:\workJava\workspace\demo\lib\jackson-mapper-asl-1.9.13.jar' 16 -libraryjars 'D:\workJava\workspace\demo\lib\log4j-1.2.16.jar' 17 -libraryjars 'D:\workJava\workspace\demo\lib\mail-1.4.7.jar' 18 -libraryjars 'D:\workJava\workspace\demo\lib\spring-web-3.1.1.RELEASE.jar' 19 -libraryjars 'D:\workJava\workspace\demo\lib\spring-webmvc-3.1.1.RELEASE.jar' 20 -libraryjars 'D:\workJava\workspace\demo\lib\xstream-1.2.2.jar' 21 -libraryjars 'C:\Program Files\Java\jre6\lib\jce.jar' 22 -libraryjars 'C:\Program Files\Java\jre6\lib\rt.jar' 23 -libraryjars 'C:\Program Files\Java\jre6\lib\javaws.jar' 24 -libraryjars 'D:\workJava\servers\tomcat-7.0.54\lib\servlet-api.jar' 25 -libraryjars 'C:\Program Files\Java\jre6\lib\jsse.jar' 26 27 -target 1.6 28 -dontshrink 29 -dontoptimize 30 -dontusemixedcaseclassnames 31 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod 32 33 34 # 设置不需要混淆的包, 可以使用通配符 * 和 *.**, 注意, 后者不包含前者 35 -keep class com.demo.common.bean.* { 36 public <fields>; 37 public <methods>; 38 *** set*(***); 39 *** get*(); 40 } 41 42 # 43 -keep class com.demo.common.config.* { 44 public <fields>; 45 public <methods>; 46 *** set*(***); 47 *** get*(); 48 } 49 50 # 51 -keep class com.demo.common.dao.*.** { 52 public <fields>; 53 public <methods>; 54 *** set*(***); 55 *** get*(); 56 } 57 58 # 59 -keep class com.demo.common.web.*.** { 60 public <fields>; 61 public <methods>; 62 *** set*(***); 63 *** get*(); 64 } 65 66 # Keep - Applications. Keep all application classes, along with their 'main' 67 # methods. 68 -keepclasseswithmembers public class * { 69 public static void main(java.lang.String[]); 70 } 71 72 # Keep names - Native method names. Keep all native class/method names. 73 -keepclasseswithmembers,includedescriptorclasses,allowshrinking class * { 74 native <methods>; 75 }