只要下回插件并添加相应的配置文件即可。本文仅是做下相关记录
1.修改pom.xml添加插件
- <plugin>
- <groupId>com.pyx4me</groupId>
- <artifactId>proguard-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>proguard</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <obfuscate>true</obfuscate>
- <proguardInclude>${basedir}/proguard.conf</proguardInclude>
- <!-- 添加依赖,这里你可以按你的需要修改 -->
- <libs>
- <lib>${java.home}/lib/rt.jar</lib>
- <lib>lib/fcexporter_jdk1.5.jar</lib>
- <lib>lib/fcexporthandler.jar</lib>
- <lib>lib/jsp-api.jar</lib>
- <lib>lib/servlet-api.jar</lib>
- </libs>
- <addMavenDescriptor>false</addMavenDescriptor>
- </configuration>
- <dependencies>
- <!-- 使用4.8版本来混淆 -->
- <dependency>
- <groupId>net.sf.proguard</groupId>
- <artifactId>proguard</artifactId>
- <version>4.8</version>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
- </plugin>
- 2.在pom.xml平级目录下添加proguard.conf文件
- # ----------------------------------
- # 通过指定数量的优化能执行
- # -optimizationpasses n
- # ----------------------------------
- -optimizationpasses 3
- # ----------------------------------
- # 混淆时不会产生形形色色的类名
- # -dontusemixedcaseclassnames
- # ----------------------------------
- -dontusemixedcaseclassnames
- # ----------------------------------
- # 指定不去忽略非公共的库类
- # -dontskipnonpubliclibraryclasses
- # ----------------------------------
- #-dontskipnonpubliclibraryclasses
- # ----------------------------------
- # 不预校验
- # -dontpreverify
- # ----------------------------------
- # -dontpreverify
- # ----------------------------------
- # 输出生成信息
- # -verbose
- # ----------------------------------
- -verbose
- #混淆时应用侵入式重载
- -overloadaggressively
- #优化时允许访问并修改有修饰符的类和类的成员
- -allowaccessmodification
- #确定统一的混淆类的成员名称来增加混淆
- -useuniqueclassmembernames
- #这里添加你不需要混淆的类
- -keep class com.zsoftware.common.cache.** {*;}
- -keep class com.zsoftware.common.constant.** {*;}
- -keep class com.zsoftware.common.dwr.** {*;}
- -keep class com.zsoftware.common.servelt.** {*;}
- -keep class com.zsoftware.common.util.** {*;}
- -keep class com.zsoftware.Component.** {*;}
- -keep class com.zsoftware.interfacepkg.** {*;}
- -keep class com.zsoftware.model.** {*;}
- -keep class com.zsoftware.view.** {*;}
- -keep class com.zsoftware.webResource.** {*;}
- -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>;
- }
时间: 2024-10-12 21:14:43