目录[-]
一、场景介绍 二、Maven 配置 1、Project1 的 pom.xml 2、Project2 的 pom.xml 三、Java 混淆前后内容比较 1、混淆前的 Project2 类 2、混淆后的 Project2 类 四、类路径中资源加载问题 五、总结两个工程 Project1,Project2(将被混淆的工程)。Project1 将通过 Maven 依赖配置的方式引用混淆后的 Project2。后面我会详细介绍 pom.xml 的配置。
该 pom.xml 比较简单主要通过 classifier 来判断是否使用混淆的 Jar(Project2)
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >org.noahx.proguard.example</ groupId > < artifactId >project1</ artifactId > < version >1.0-SNAPSHOT</ version > < dependencies > < dependency > < groupId >org.noahx.proguard.example</ groupId > < artifactId >project2</ artifactId > < classifier >pg</ classifier > <!--如果不想依赖混淆的包,请注释掉该行--> < version >1.0-SNAPSHOT</ version > </ dependency > </ dependencies > </ project >
pom.xml 中配置的 proguard-maven-plugin 来做混淆,详细说明见注释。
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >org.noahx.proguard.example</ groupId > < artifactId >project2</ artifactId > < version >1.0-SNAPSHOT</ version > < build > < plugins > < plugin > < groupId >com.github.wvengen</ groupId > < artifactId >proguard-maven-plugin</ artifactId > < version >2.0.7</ version > < executions > < execution > < phase >package</ phase > < goals > < goal >proguard</ goal > </ goals > </ execution > </ executions > < configuration > < attach >true</ attach > < attachArtifactClassifier >pg</ attachArtifactClassifier > <!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 --> <