在网上找了很多关于代码混淆的例子,最终结合网上知识以及自己的项目实现了代码混淆,实现过程如下:
1、在pom.xml文件的
<build>
<finalName>asfinalName>
build>
中加入如下配置:
<plugins>
<plugin>
<groupId>com.github.wvengengroupId>
<artifactId>proguard-maven-pluginartifactId>
<version>2.0.11version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>proguardgoal>
goals>
execution>
executions>
<configuration>
<attach>trueattach>
<obfuscate>trueobfuscate>
<attachArtifactClassifier>pgattachArtifactClassifier>
<options>
<option>-target 1.7option>
<option>-dontshrinkoption>
<option>-dontoptimizeoption>
<option>-dontskipnonpubliclibraryclassesoption>
<option>-dontskipnonpubliclibraryclassmembersoption>
<option>-allowaccessmodificationoption>
<option>-useuniqueclassmembernamesoption>
<option>-keeppackagenamesoption>
<option>-keepattributesExceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethodoption>
<option>-keepclassmemberspublic class * {void set*(***);*** get*();}option>
<option>-keep classcom.zykj.dbCon.DBConnect{ *; }option>
<option>-keep classcom.zykj.util.Toolsoption>
<option>-keep classcom.zykj.httpClient.HttpDealoption>
<option>-keep classcom.zykj.controller.** { <methods>; }option>
options>
<outjar>${project.build.finalName}-pg.jaroutjar>
<libs>
<lib>${java.home}/lib/rt.jarlib>
<lib>${java.home}/lib/jce.jarlib>
<lib>${java.home}/lib/security/local_policy.jarlib>
<lib>${java.home}/lib/security/US_export_policy.jarlib>
<lib>${java.home}/lib/ext/sunjce_provider.jarlib>
libs>
<inFilter>com/zykj/**inFilter>
<injar>classesinjar>
<outputDirectory>${project.build.directory}outputDirectory>
configuration>
plugin>
plugins>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
includes>
resource>
<resource>
<directory>src/main/javadirectory>
<excludes>
<exclude>**/*.javaexclude>
<exclude>**/.svn/*exclude>
excludes>
resource>
resources>
2、在myeclipse中右键项目选择Run As-Maven build. . .
在Goals中填写cleanpackage -DskipTests -X
点击按钮Run
3、在项目的target目录下生成如下几个文件:
其中
classes-pg.jar 混淆后的classes文件,里面包含完整的项目结构
proguard_map.txt 混淆内容的映射
proguard_seed.txt 参与混淆的类
4、将classes-pg.jar解压如下:
其中com文件夹就是混淆后的类文件夹(内容为混淆后的class文件)。
5、利用myelicpse打包整个项目成war包,用winrar或者好压打开war包,找到WEB-INF\classes下的com文件夹,将解压出来的com文件夹及其内容替换之。
6、把war放到服务器上运行,生成的class文件就是混淆文件了。