maven+proguard第三方jar打包混淆

几篇有价值的参考blog:

  1. http://blog.csdn.net/fastthinking/article/details/39155733(proguard基础 )
  2. http://www.tuicool.com/articles/QRzMz2(我是参照这篇配置的)
  3. http://www.blogjava.net/ideame/archive/2010/02/01/311486.html(混淆过程中报错, 看到了这篇文章,但最后发现我的问题跟他这个不一样)
  4. http://blog.csdn.net/testcs_dn/article/details/45623211(这个也不错)

环境:

Apache Maven 3.3.9 
Maven home: D:\Program Files\apache-maven-3.3.9
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_74\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"

我的maven配置

<plugins>
     <plugin><!--将所有的依赖达到一个jar包里-->
         <artifactId>maven-assembly-plugin</artifactId>
         <configuration>
             <archive>
                 <manifest>
                     <!--这里要替换成jar包main方法所在类-->
                     <mainClass>com.sq.platform.datacube.core.impl.DataCube</mainClass>
                 </manifest>
             </archive>
             <descriptorRefs>
                 <descriptorRef>jar-with-dependencies</descriptorRef>
             </descriptorRefs>
         </configuration>
         <executions>
             <execution>
                 <id>make-assembly</id> <!-- this is used for inheritance merges -->
                 <phase>package</phase> <!-- 指定在打包节点执行jar包合并操作 -->
                 <goals>
                     <goal>single</goal>
                 </goals>
             </execution>
         </executions>
     </plugin>
     <plugin><!--用混淆插件混淆代码-->
         <groupId>com.github.wvengen</groupId>
         <artifactId>proguard-maven-plugin</artifactId>
         <version>2.0.11</version>
         <executions>
             <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>proguard</goal>
                 </goals>
             </execution>
         </executions>
         <configuration>
             <attach>true</attach>
             <attachArtifactClassifier>pg</attachArtifactClassifier>
             <!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 -->
             <options> <!-- 详细配置方式参考 ProGuard 官方文档 -->
                 <option>-ignorewarnings</option> <!--忽略所有告警-->
                 <option>-dontshrink</option>   <!--不做 shrink -->
                 <option>-dontoptimize</option> <!--不做 optimize -->
                 <option>-dontskipnonpubliclibraryclasses </option>
                 <option>-dontskipnonpubliclibraryclassmembers </option>
                 <option>-dontnote </option>

                 <option>-keepattributes Signature</option>

                 <!--保持源码名与行号(异常时有明确的栈信息),注解(默认会过滤掉所有注解,会影响框架的注解)-->
                 <option>-keepattributes Exceptions,InnerClasses,*Annotation*,Signature,LineNumberTable</option>


                                <!-- 保持bean类名与属性名不变不变 -->
                 <option>-keep class com.sq.platform.datacube.model.**</option>
                 <option>-keepclassmembers class com.sq.platform.datacube.model.** { *;}</option>
                 <!-- 保持对外的接口性质类对外的类名与方法名不变 -->
                 <option>-keep class com.sq.platform.datacube.core.**</option>
                 <option>-keepclassmembers class com.sq.platform.datacube.core.** { *;}</option>

                 <option>-keep class com.sq.platform.datacube.exception.**</option>
                 <option>-keepclassmembers class com.sq.platform.datacube.exception.** { *;}</option>

                                <!--以下配置第三方包不参与混淆-->
                 <option>-keepclassmembers class com.hopechart.dcroute.** { *;}</option>
                 <option>-dontwarn com.hopechart.dcroute.**</option>
                 <option>-keep class com.hopechart.dcroute.** {*;}</option>

                 <option>-keepclassmembers class com.hopechart.cloud.** { *;}</option>
                 <option>-dontwarn com.hopechart.cloud.**</option>
                  <option>-keep class com.hopechart.cloud.** {*;}</option>

                 <option>-keepclassmembers class com.hopechart.jcc.** { *;}</option>
                 <option>-dontwarn com.hopechart.jcc.**</option>
                 <option>-keep class com.hopechart.jcc.** {*;}</option>

                 <option>-keepclassmembers class oracle.** { *;}</option>
                 <option>-dontwarn oracle.**</option>
                 <option>-keep class oracle.**</option>

                 <option>-keepclassmembers class org.aopalliance.** { *;}</option>
                 <option>-dontwarn org.aopalliance.**</option>
                 <option>-keep class org.aopalliance.**</option>

                 <option>-keepclassmembers class org.apache.commons.** { *;}</option>
                 <option>-dontwarn org.apache.commons.**</option>
                 <option>-keep class org.apache.commons.**</option>

                 <option>-keepclassmembers class org.apache.log4j.** { *;}</option>
                 <option>-dontwarn org.apache.log4j.**</option>
                 <option>-keep class org.apache.log4j.**</option>

                 <option>-keepclassmembers  class org.slf4j.** { *;}</option>
                 <option>-dontwarn  org.slf4j.**</option>
                 <option>-keep class org.slf4j.**</option>

                 <option>-keepclassmembers class org.springframework.** { *;}</option>
                 <option>-dontwarn  org.springframework.**</option>
                 <option>-keep class org.springframework.**</option>

             </options>
             <!--指定混淆的jar包,我这里是将上一步输出的jar包进行混淆-->
             <injar>datacube-1.0-SNAPSHOT-jar-with-dependencies.jar</injar>
             <!--指定输出的jar包名-->
             <outjar>${project.build.finalName}-pg</outjar>
             <obfuscate>true</obfuscate>
             <!-- 添加依赖,必须添加,不然会报一些莫名错误-->
             <libs>
                 <lib>${java.home}/lib/rt.jar</lib>
                 <lib>${java.home}/lib/jce.jar</lib>
                 <lib>D:/workspace3/datacube/lib/apache-axiom-api-1.2.7.jar</lib>
                 <lib>D:/workspace3/datacube/lib/axis2-kernel-1.7.1.jar</lib>
             </libs>
         </configuration>
     </plugin>
</plugins>

混淆后结果

这里写图片描述

混淆中遇见的错误:

Error: Can’t find common super class of ………
解决方法:添加依赖的jar包

 <libs>
     <lib>${java.home}/lib/rt.jar</lib>
     <lib>${java.home}/lib/jce.jar</lib>
     <lib>D:/workspace3/datacube/lib/apache-axiom-api-1.2.7.jar</lib>
     <lib>D:/workspace3/datacube/lib/axis2-kernel-1.7.1.jar</lib>
 </libs>
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页