Add proguard to Maven to confuse code

Source: Internet
Author: User

You want to confuse code when you package a category in an existing web project. Because Maven is used for management, Google found that similar plug-ins already exist. You only need to go back to the plug-in and add the corresponding configuration file. This article only makes relevant records

1. Modify Pom. XML to add a plug-in

<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> <! -- Add dependency. Here you can modify as needed --> <libs> <lib >$ {Java. home}/lib/RT. jar </lib> <lib> lib/fcexporter_jdk1.5.jar </lib> <lib> lib/fcexporthandler. </lib> <lib> lib/jsp-api.jar </lib> <lib> lib/servlet-api.jar </lib> </libs> <addmavendescriptor> false </addmavendescriptor> </Configuration> <dependencies> <! -- Use version 4.8 for obfuscation --> <dependency> <groupid> net. SF. proguard </groupid> <artifactid> proguard </artifactid> <version> 4.8 </version> <scope> runtime </scope> </dependency> </dependencies> </plugin>

2. Add the proguard. conf file in the Pom. xml level directory.

# Dependencies # execution can be performed through a specified number of optimizations #-optimizationpasses N # optimized optimizationpasses 3 # classes are not generated in obfuscation #-dontusemixedcaseclassnames # specified dontusemixedcaseclassnames # ignore non-public library classes #-libraries # classes #-dontskipnonpubliclibraryclasses # classes # non-Pre-validation #-dontpreverify # classes #-dontpreverify # outputs generated information #-verbose # explain verbose # application intrusive overload during obfuscation-overloadaggressively # Allow access to and modify modifier-related classes and Class Members-allowaccessmodification # determine the name of a unified obfuscation class member to add obfuscation-useuniqueclassmembernames # Add the class you do not need to confuse here-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 # --------- protect the field names in all entities ----------- keepclassmembers class * implements Java. io. serializable {<fields >;}# --------- all method names in the protection class ------------- keepclassmembers class * {Public <Methods> ;}

3. You can package the MVN package to find that the output result package has been mixed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.