1.maven打包:html
一直以來我都沒太注意過在myeclipse下使用run as來clean竟然對項目的target目錄沒有進行操做,要讓操做有效,須要進入到maven build...選項下,進行clean,而後再使用process resources來加入配置文件,再使用compile--》package來打包,同時,值得注意的是,maven在進行打包時默認只把java文件打包進war,若是在非資源路徑下,有配置文件,如mybits的mapper.xml文件,須要在maven裏邊指定一下,不然打包會失敗。java
<build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.tld</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.tld</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
tips:通常若是不特別指定,maven項目在打包後會改變項目名稱,如你的項目原來叫test,打包後會變成test0.0.1-SNAPSHOT,看起來很不爽,爲了解決這一問題,須要加入以下配置:git
<artifactId>test</artifactId> <build> <finalName>test</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <packagingExcludes>WEB-INF/web.xml</packagingExcludes> </configuration> </plugin> </plugins> </build>
2.progard混淆配置部分:github
<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> <obfuscate>true</obfuscate> <attachArtifactClassifier>pg</attachArtifactClassifier> <options> <option>-target 1.8</option> <option>-dontshrink</option> <option>-dontoptimize</option> <option>-dontskipnonpubliclibraryclasses</option> <option>-dontskipnonpubliclibraryclassmembers</option> <option>-dontusemixedcaseclassnames</option> <option>-allowaccessmodification</option> <option>-useuniqueclassmembernames</option> <option>-keeppackagenames</option> <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod</option> <option>-keepclassmembers public class * {void set*(***);*** get*();}</option> <!--原生servlet都是經過方法名調用接口的,因此,得保留類名和方法名 --> <option>-keep class **.list.servlet.**{*;}</option> <option>-keep class **.zxf.servlet.**{*;}</option> <option>-keep class **.controller.**</option> <!-- dao層接口的類名和方法不混淆 --> <option>-keep class **.dao.**{ <methods>; }</option> <!-- 不混淆實體類的方法和屬性,由於在配置文件中有引用--> <option>-keep class **.domain.** {*;}</option> <!-- 不混淆jsp頁面引入的類和屬性 --> <option>-keep class com.lum.interface_util.** {*;}</option> <option>-keep class com.java.zxf.util.ShowString {*;}</option> </options> <outjar>classes-autotest.jar</outjar> <libs> <lib>${java.home}/lib/rt.jar</lib> </libs> <injar>classes</injar> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin>
3.混淆說明:你在混淆前,須要仔細分析你的項目,看看那些是必須保持類名不變的,那些是類名能夠變,方法名能夠變的,那些是能夠隨意變的,只有在搞清楚這些以後,你的混淆工做纔是有保障的,即即實現了混淆,也保證了代碼的可執行性,混淆結果截圖以下:web
反編譯後的效果:sql
5.總結:我的分析得出不能混淆的類主要有這些:①在web.xml裏邊配置的servlet,那麼servlet的名稱和方法名都不能進行混淆;②與數據庫有交互的,主要包括實體類,dao層(這種是經過mapper.xml形式寫的sql);③在jsp頁面導入的類,如常量類,實體類等,需保證類名和變量名都不能混淆數據庫