一步步教你使用Proguard混淆Java源代码 [url]http://java-server.iteye.com/blog/1166114[/url]
直接使用mvn package可能直接出错,所以先用jar:jar命令得到jar文件,在使用proguard:proguard混淆。
命令在idea的Maven Projects查看。
参考:[url]http://zhengchao123.iteye.com/blog/1872424[/url]
com.pyx4me=>com.github.wvengen,版本号要变成2.0.7
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>4.9</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
proguard.conf
[color=darkblue]# ----------------------------------
# 通过指定数量的优化能执行
# -optimizationpasses n
# ----------------------------------
-optimizationpasses 3
# ----------------------------------
# 混淆时不会产生形形色色的类名
# -dontusemixedcaseclassnames
# ----------------------------------
-dontusemixedcaseclassnames
# ----------------------------------
# 指定不去忽略非公共的库类
# -dontskipnonpubliclibraryclasses
# ----------------------------------
#-dontskipnonpubliclibraryclasses
# ----------------------------------
# 不预校验
# -dontpreverify
# ----------------------------------
# -dontpreverify
# ----------------------------------
# 输出生成信息
# -verbose
# ----------------------------------
-verbose
#混淆时应用侵入式重载
-overloadaggressively
#优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification
#确定统一的混淆类的成员名称来增加混淆
-useuniqueclassmembernames
#这里添加你不需要混淆的类
-dontwarn javax.crypto.**
-keep class javax.crypto.**
-keep class com.rh.hasp.util.** {*;}
#-keep class com.zsoftware.common.constant.** {*;}
-keep public class * extends javax.servlet.Servlet
-keepdirectories **
-keepattributes **
#-keepnames class * implements java.io.Serializable
# ---------保护所有实体中的字段名称----------
-keepclassmembers class * implements java.io.Serializable {
<fields>;
}
# --------- 保护类中的所有方法名 ------------
-keepclassmembers class * {
public <methods>;
}
[/color]
执行:mvn package
输出:
[color=darkblue][INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar
[INFO]
[INFO] --- proguard-maven-plugin:2.0.6:proguard (default) @ rh-hasp ---
[INFO] execute ProGuard [-injars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar'(!META-INF/maven/**), -outjars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar', -include, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/proguard.conf', -libraryjars, '/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar', -libraryjars, '/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar', -libraryjars, '/usr/java/jdk1.7.0_51/jre/lib/rt.jar', -printmapping, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt', -printseeds, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_seeds.txt']
[INFO] proguard jar: /home/pandy/m2/repository/net/sf/proguard/proguard-base/4.9/proguard-base-4.9.jar
[proguard] ProGuard, version 4.9
[proguard] Reading input...
[proguard] Reading program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[proguard] Reading library jar [/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar]
[proguard] Reading library jar [/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar]
[proguard] Reading library jar [/usr/java/jdk1.7.0_51/jre/lib/rt.jar]
[proguard] Initializing...
[proguard] Note: the configuration refers to the unknown class 'javax.servlet.Servlet'
[proguard] Note: there were 1 references to unknown classes.
[proguard] You should check your configuration for typos.
[proguard] Ignoring unused library classes...
[proguard] Original number of library classes: 19278
[proguard] Final number of library classes: 19278
[proguard] Printing kept classes, fields, and methods...
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard] Original number of program classes: 8
[proguard] Final number of program classes: 8
[proguard] Inlining subroutines...
[proguard] Optimizing...
[proguard] Number of finalized classes: 5
[proguard] Number of vertically merged classes: 0
[proguard] Number of horizontally merged classes: 0
[proguard] Number of removed write-only fields: 3
[proguard] Number of privatized fields: 12
[proguard] Number of inlined constant fields: 0
[proguard] Number of privatized methods: 0
[proguard] Number of staticized methods: 1
[proguard] Number of finalized methods: 45
[proguard] Number of removed method parameters: 0
[proguard] Number of inlined constant parameters: 2
[proguard] Number of inlined constant return values: 0
[proguard] Number of inlined short method calls: 0
[proguard] Number of inlined unique method calls: 13
[proguard] Number of inlined tail recursion calls: 0
[proguard] Number of merged code blocks: 2
[proguard] Number of variable peephole optimizations: 72
[proguard] Number of arithmetic peephole optimizations: 0
[proguard] Number of cast peephole optimizations: 0
[proguard] Number of field peephole optimizations: 1
[proguard] Number of branch peephole optimizations: 36
[proguard] Number of string peephole optimizations: 11
[proguard] Number of simplified instructions: 3
[proguard] Number of removed instructions: 33
[proguard] Number of removed local variables: 2
[proguard] Number of removed exception blocks: 3
[proguard] Number of optimized local variable frames: 25
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard] Original number of program classes: 8
[proguard] Final number of program classes: 8
[proguard] Optimizing...
[proguard] Number of finalized classes: 0
[proguard] Number of vertically merged classes: 0
[proguard] Number of horizontally merged classes: 0
[proguard] Number of removed write-only fields: 0
[proguard] Number of privatized fields: 0
[proguard] Number of inlined constant fields: 0
[proguard] Number of privatized methods: 0
[proguard] Number of staticized methods: 0
[proguard] Number of finalized methods: 0
[proguard] Number of removed method parameters: 1
[proguard] Number of inlined constant parameters: 0
[proguard] Number of inlined constant return values: 0
[proguard] Number of inlined short method calls: 0
[proguard] Number of inlined unique method calls: 0
[proguard] Number of inlined tail recursion calls: 0
[proguard] Number of merged code blocks: 0
[proguard] Number of variable peephole optimizations: 4
[proguard] Number of arithmetic peephole optimizations: 0
[proguard] Number of cast peephole optimizations: 0
[proguard] Number of field peephole optimizations: 0
[proguard] Number of branch peephole optimizations: 1
[proguard] Number of string peephole optimizations: 2
[proguard] Number of simplified instructions: 0
[proguard] Number of removed instructions: 50
[proguard] Number of removed local variables: 1
[proguard] Number of removed exception blocks: 0
[proguard] Number of optimized local variable frames: 1
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard] Original number of program classes: 8
[proguard] Final number of program classes: 8
[proguard] Optimizing...
[proguard] Number of finalized classes: 0
[proguard] Number of vertically merged classes: 0
[proguard] Number of horizontally merged classes: 0
[proguard] Number of removed write-only fields: 0
[proguard] Number of privatized fields: 0
[proguard] Number of inlined constant fields: 0
[proguard] Number of privatized methods: 0
[proguard] Number of staticized methods: 0
[proguard] Number of finalized methods: 0
[proguard] Number of removed method parameters: 0
[proguard] Number of inlined constant parameters: 0
[proguard] Number of inlined constant return values: 0
[proguard] Number of inlined short method calls: 0
[proguard] Number of inlined unique method calls: 0
[proguard] Number of inlined tail recursion calls: 0
[proguard] Number of merged code blocks: 0
[proguard] Number of variable peephole optimizations: 0
[proguard] Number of arithmetic peephole optimizations: 0
[proguard] Number of cast peephole optimizations: 0
[proguard] Number of field peephole optimizations: 0
[proguard] Number of branch peephole optimizations: 0
[proguard] Number of string peephole optimizations: 2
[proguard] Number of simplified instructions: 0
[proguard] Number of removed instructions: 6
[proguard] Number of removed local variables: 0
[proguard] Number of removed exception blocks: 0
[proguard] Number of optimized local variable frames: 0
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard] Original number of program classes: 8
[proguard] Final number of program classes: 8
[proguard] Obfuscating...
[proguard] Printing mapping to [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt]...
[proguard] Preverifying...
[proguard] Writing output...
[proguard] Preparing output jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar]
[proguard] Copying resources from program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1-lib.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS[/color]
这时就已经好了,但是包结构都变了,成了a,b,c,d ....的了
虽然是混淆加密了,但是外部也不能再直接使用类来...地去引用了