使用proguard混淆Java代码

对于Java Web项目,使用Netbeans作为IDE环境,想实现自动混淆class文件。因为Web项目,所以一些类是不能混淆的:

1. web.xml中涉及的类名称、package名称
2. 返回前端的数据涉及到的类名称、属性名称…

proguard的运行方法是执行proguard.sh @<cfg_file.cfg>

web项目,一般输入需要混淆的是WEB-INF/classes/下的相关class文件,要把WEB-INF/lib/下的相关jar文件都设置为libraryjars

proguard配置文件示例:

-injars /Users/xxx/NetBeansProjects/yyy/build/web/WEB-INF/classes
-outjars /Users/xxx/neto_classes

-dontshrink
-dontoptimize

-libraryjars /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/rt.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/asm-all-repackaged-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/cglib-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/cglib-2.2.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-beanutils-1.8.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-codec-1.3.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-collections-3.2.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-digester-2.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-fileupload-1.2.2.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-httpclient-3.0.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-io-2.0.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-lang-2.5.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-logging-1.1.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-logging.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-pool-1.6.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/commons-primitives-1.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/eclipselink.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/ezmorph-1.0.6.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/guava-14.0.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/hk2-api-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/hk2-locator-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/hk2-utils-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/javax.annotation-api-1.2.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/javax.inject-2.2.0-b21.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/javax.servlet-api-3.0.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/javax.ws.rs-api-2.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jaxb-api-2.2.7.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-client.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-common.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-container-servlet-core.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-container-servlet.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-entity-filtering-2.5.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-media-moxy-2.5.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/jersey-server.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/json-lib-2.4-jdk15.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/ojdbc5.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/org-apache-commons-logging.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/org.osgi.core-4.2.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/osgi-resource-locator-1.0.1.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/persistence-api-1.0.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-aop-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-aspects-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-beans-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-build-src-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-context-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-context-support-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-core-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-expression-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-framework-bom-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-instrument-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-instrument-tomcat-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-jdbc-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-jms-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-orm-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-oxm-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-struts-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-test-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-tx-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-web-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-webmvc-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/spring-webmvc-portlet-3.2.7.RELEASE.jar
-libraryjars /Users/changzhenghe/NetBeansProjects/RmsPlus/build/web/WEB-INF/lib/validation-api-1.1.0.Final.jar

-ignorewarnings
-keeppackagenames com.**
-keeppackagenames sun.**
-keeppackagenames oracle.**
-keeppackagenames org.**
-keeppackagenames java.**
-keeppackagenames javax.**
-keeppackagenames jdk.**
-keeppackagenames net.sf.**

-keepattributes *Annotation*

# Keep – Applications. Keep all application classes, along with their ‘main’
# methods.
#-keepclasseswithmembers public class * {
# public static void main(java.lang.String[]);
#}

# Also keep – Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
public **[] values();
public ** valueOf(java.lang.String);
}

# Also keep – Database drivers. Keep all implementations of java.sql.Driver.
-keep class * extends java.sql.Driver

# Also keep – Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI,
# along with the special ‘createUI’ method.
-keep class * extends javax.swing.plaf.ComponentUI {
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent);
}

# Keep names – Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}

-keep class * extends javax.servlet.http.HttpServlet
-keep class net.skyatlas.ee.RmsPlus.webapi.*
-keep class net.skyatlas.ee.RmsPlus.domain.*
-keep class net.skyatlas.ee.RmsPlus.comm.*
-keep class net.skyatlas.ee.RmsPlus.util.RSAPemCoder

-keepclassmembers class net.skyatlas.ee.RmsPlus.comm.* {
private <fields>;
public <methods>;
}

-keepclassmembers class net.skyatlas.ee.RmsPlus.domain.* {
private <fields>;
public <methods>;
}

#-keepclassmembers class net.skyatlas.ee.RmsPlus.comm.DateAdapter {
# private <fields>;
# public <methods>;
#}

#-keep public class com.bpo.offerlist.util.Constant
#-keepclassmembers class com.bpo.offerlist.util.Constant {
# public protected private <fields>;
#}
#
#-keep public class com.bpo.offerlist.manager.JJJ
#-keepclassmembers class com.bpo.offerlist.manager.JJJ {
# public <methods>;
#}
#
#-keep public class com.bpo.offerlist.util.DebugHelper
#-keepclassmembers class com.bpo.offerlist.util.DebugHelper {
# public <methods>;
# public static <methods>;
# public protected private <fields>;
#}

Leave Comment

电子邮件地址不会被公开。 必填项已用*标注