`

maven中添加proguard来混淆代码

 
阅读更多
一步步教你使用Proguard混淆Java源代码 http://java-server.iteye.com/blog/1166114


直接使用mvn package可能直接出错,所以先用jar:jar命令得到jar文件,在使用proguard:proguard混淆。
命令在idea的Maven Projects查看。


参考:http://zhengchao123.iteye.com/blog/1872424
com.pyx4me=>com.github.wvengen,版本号要变成2.0.7
<plugin>  
    <groupId>com.pyx4me</groupId>  
    <artifactId>proguard-maven-plugin</artifactId>  
    <version>2.0.6</version>  
    <executions>  
        <execution>  
            <phase>package</phase>  
            <goals>  
                <goal>proguard</goal>  
            </goals>  
        </execution>  
    </executions>  
    <configuration>  
        <source>1.7</source>  
        <target>1.7</target>  
        <encoding>UTF-8</encoding>  
        <libs>  
            <lib>${java.home}/lib/rt.jar</lib>  
            <lib>${java.home}/lib/jsse.jar</lib>  
        </libs>   
    </configuration>  
                  
    <dependencies>  
        <dependency>  
            <groupId>net.sf.proguard</groupId>  
            <artifactId>proguard-base</artifactId>  
            <version>4.9</version>  
            <scope>runtime</scope>  
        </dependency>  
    </dependencies>  
</plugin>  

proguard.conf
# ----------------------------------
#  通过指定数量的优化能执行
#  -optimizationpasses n
# ----------------------------------
-optimizationpasses 3

# ----------------------------------
#   混淆时不会产生形形色色的类名
#   -dontusemixedcaseclassnames
# ----------------------------------
-dontusemixedcaseclassnames
# ----------------------------------
#      指定不去忽略非公共的库类
#  -dontskipnonpubliclibraryclasses
# ----------------------------------
#-dontskipnonpubliclibraryclasses

# ----------------------------------
#       不预校验
#    -dontpreverify
# ----------------------------------
# -dontpreverify

# ----------------------------------
#      输出生成信息
#       -verbose
# ----------------------------------
-verbose

#混淆时应用侵入式重载
-overloadaggressively

#优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification
#确定统一的混淆类的成员名称来增加混淆
-useuniqueclassmembernames



#这里添加你不需要混淆的类
-dontwarn javax.crypto.**
-keep class javax.crypto.**
-keep  class com.rh.hasp.util.** {*;}
#-keep  class com.zsoftware.common.constant.** {*;}

-keep public class * extends  javax.servlet.Servlet

-keepdirectories  **
-keepattributes **


#-keepnames class * implements java.io.Serializable
# ---------保护所有实体中的字段名称----------
-keepclassmembers class * implements java.io.Serializable {
    <fields>;
}

# --------- 保护类中的所有方法名 ------------
-keepclassmembers class * {
public <methods>;
}

执行:mvn package
输出:
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar
[INFO]
[INFO] --- proguard-maven-plugin:2.0.6:proguard (default) @ rh-hasp ---
[INFO] execute ProGuard [-injars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar'(!META-INF/maven/**), -outjars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar', -include, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/proguard.conf', -libraryjars, '/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar', -libraryjars, '/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar', -libraryjars, '/usr/java/jdk1.7.0_51/jre/lib/rt.jar', -printmapping, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt', -printseeds, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_seeds.txt']
[INFO] proguard jar: /home/pandy/m2/repository/net/sf/proguard/proguard-base/4.9/proguard-base-4.9.jar
[proguard] ProGuard, version 4.9
[proguard] Reading input...
[proguard] Reading program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[proguard] Reading library jar [/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar]
[proguard] Reading library jar [/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar]
[proguard] Reading library jar [/usr/java/jdk1.7.0_51/jre/lib/rt.jar]
[proguard] Initializing...
[proguard] Note: the configuration refers to the unknown class 'javax.servlet.Servlet'
[proguard] Note: there were 1 references to unknown classes.
[proguard]       You should check your configuration for typos.
[proguard] Ignoring unused library classes...
[proguard]   Original number of library classes: 19278
[proguard]   Final number of library classes:    19278
[proguard] Printing kept classes, fields, and methods...
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]   Original number of program classes: 8
[proguard]   Final number of program classes:    8
[proguard] Inlining subroutines...
[proguard] Optimizing...
[proguard]   Number of finalized classes:                 5
[proguard]   Number of vertically merged classes:         0
[proguard]   Number of horizontally merged classes:       0
[proguard]   Number of removed write-only fields:         3
[proguard]   Number of privatized fields:                 12
[proguard]   Number of inlined constant fields:           0
[proguard]   Number of privatized methods:                0
[proguard]   Number of staticized methods:                1
[proguard]   Number of finalized methods:                 45
[proguard]   Number of removed method parameters:         0
[proguard]   Number of inlined constant parameters:       2
[proguard]   Number of inlined constant return values:    0
[proguard]   Number of inlined short method calls:        0
[proguard]   Number of inlined unique method calls:       13
[proguard]   Number of inlined tail recursion calls:      0
[proguard]   Number of merged code blocks:                2
[proguard]   Number of variable peephole optimizations:   72
[proguard]   Number of arithmetic peephole optimizations: 0
[proguard]   Number of cast peephole optimizations:       0
[proguard]   Number of field peephole optimizations:      1
[proguard]   Number of branch peephole optimizations:     36
[proguard]   Number of string peephole optimizations:     11
[proguard]   Number of simplified instructions:           3
[proguard]   Number of removed instructions:              33
[proguard]   Number of removed local variables:           2
[proguard]   Number of removed exception blocks:          3
[proguard]   Number of optimized local variable frames:   25
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]   Original number of program classes: 8
[proguard]   Final number of program classes:    8
[proguard] Optimizing...
[proguard]   Number of finalized classes:                 0
[proguard]   Number of vertically merged classes:         0
[proguard]   Number of horizontally merged classes:       0
[proguard]   Number of removed write-only fields:         0
[proguard]   Number of privatized fields:                 0
[proguard]   Number of inlined constant fields:           0
[proguard]   Number of privatized methods:                0
[proguard]   Number of staticized methods:                0
[proguard]   Number of finalized methods:                 0
[proguard]   Number of removed method parameters:         1
[proguard]   Number of inlined constant parameters:       0
[proguard]   Number of inlined constant return values:    0
[proguard]   Number of inlined short method calls:        0
[proguard]   Number of inlined unique method calls:       0
[proguard]   Number of inlined tail recursion calls:      0
[proguard]   Number of merged code blocks:                0
[proguard]   Number of variable peephole optimizations:   4
[proguard]   Number of arithmetic peephole optimizations: 0
[proguard]   Number of cast peephole optimizations:       0
[proguard]   Number of field peephole optimizations:      0
[proguard]   Number of branch peephole optimizations:     1
[proguard]   Number of string peephole optimizations:     2
[proguard]   Number of simplified instructions:           0
[proguard]   Number of removed instructions:              50
[proguard]   Number of removed local variables:           1
[proguard]   Number of removed exception blocks:          0
[proguard]   Number of optimized local variable frames:   1
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]   Original number of program classes: 8
[proguard]   Final number of program classes:    8
[proguard] Optimizing...
[proguard]   Number of finalized classes:                 0
[proguard]   Number of vertically merged classes:         0
[proguard]   Number of horizontally merged classes:       0
[proguard]   Number of removed write-only fields:         0
[proguard]   Number of privatized fields:                 0
[proguard]   Number of inlined constant fields:           0
[proguard]   Number of privatized methods:                0
[proguard]   Number of staticized methods:                0
[proguard]   Number of finalized methods:                 0
[proguard]   Number of removed method parameters:         0
[proguard]   Number of inlined constant parameters:       0
[proguard]   Number of inlined constant return values:    0
[proguard]   Number of inlined short method calls:        0
[proguard]   Number of inlined unique method calls:       0
[proguard]   Number of inlined tail recursion calls:      0
[proguard]   Number of merged code blocks:                0
[proguard]   Number of variable peephole optimizations:   0
[proguard]   Number of arithmetic peephole optimizations: 0
[proguard]   Number of cast peephole optimizations:       0
[proguard]   Number of field peephole optimizations:      0
[proguard]   Number of branch peephole optimizations:     0
[proguard]   Number of string peephole optimizations:     2
[proguard]   Number of simplified instructions:           0
[proguard]   Number of removed instructions:              6
[proguard]   Number of removed local variables:           0
[proguard]   Number of removed exception blocks:          0
[proguard]   Number of optimized local variable frames:   0
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]   Original number of program classes: 8
[proguard]   Final number of program classes:    8
[proguard] Obfuscating...
[proguard] Printing mapping to [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt]...
[proguard] Preverifying...
[proguard] Writing output...
[proguard] Preparing output jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar]
[proguard]   Copying resources from program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1-lib.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

这时就已经好了,但是包结构都变了,成了a,b,c,d ....的了
虽然是混淆加密了,但是外部也不能再直接使用类来...地去引用了
分享到:
评论

相关推荐

    SpringBoot + proguard+maven多模块实现代码混淆

    基于SpringBoot+Maven多模块工程利用proguard组件实现代码混淆的代码demo,代码清晰完整,导入idea或eclipse即可运行。 使用 proguard 混淆代码只能增加阅读和理解的难度, 并不能百分百保证代码安全。常用的应用...

    springboot工程(单个maven工程)利用proguard实现代码混淆

    基于springboot搭建一个简单案例,利用proguard插件实现代码混淆,增加源代码的阅读和理解的难度, 并不能百分百保证代码安全。常用的应用场景是项目需要部署到客户机器上,一定程度上防止代码泄露。 ProGuard 是一个...

    实现maven管理的Javaweb项目的proguard代码混淆功能

    本文将深入探讨如何在Maven管理的Java Web项目中集成ProGuard工具来实现代码混淆功能,以及在过程中可能遇到的问题及解决方案。 首先,让我们了解什么是ProGuard。ProGuard是一个开源的Java字节码混淆器、优化器和...

    springboot工程(单个maven工程)利用proguard实现代码混淆 java demo案例

    要在Spring Boot的Maven工程中使用ProGuard,我们需要添加`maven-proguard-plugin`插件到`pom.xml`文件中。配置大致如下: ```xml &lt;groupId&gt;com.github.wvengen&lt;/groupId&gt; &lt;artifactId&gt;proguard-maven-...

    MavenWEB项目使用ProGuard进行混淆,最佳解决方案.docx

    本文主要介绍了如何使用 ProGuard 对 Maven WEB 项目进行混淆,解决了 WEB 项目中混淆的难题。文章首先介绍了混淆的必要性,然后详细介绍了 WEB 项目的结构和 Maven 配置文件(pom.xml),最后展示了如何使用 ...

    使用Maven控件proguard-maven-plugin给可执行jar文件混淆

    总的来说,使用`proguard-maven-plugin`可以方便地在Maven项目中实现代码混淆,提高代码的安全性。在实际应用中,应根据项目需求调整混淆规则,确保混淆后的代码仍能正确运行。同时,还需要注意混淆可能带来的调试...

    Java+IDEA+maven混淆打包

    在`pom.xml`文件中,我们需要添加`maven-jar-plugin`插件来打包Java项目。以下是一个基本的配置示例: ```xml &lt;groupId&gt;org.apache.maven.plugins &lt;artifactId&gt;maven-jar-plugin &lt;version&gt;3.2.0 ...

    WEB Maven 项目 ProGuard 混淆方案

    WEB Maven 项目 ProGuard 混淆方案 POM文件,包含详细混淆注释 具体请参考博客: http://blog.csdn.net/wltj920/article/details/48970869#comments

    proguard程序混淆器

    ProGuard可以方便地与构建工具如Ant、Maven、Gradle集成,自动化混淆、优化和打包流程。在Android Studio中,ProGuard配置通常在`build.gradle`文件中完成,通过`minifyEnabled true`开启混淆,并指定配置文件路径...

    Java+IDEA+Maven混淆打包

    本教程将详细讲解如何在IntelliJ IDEA(IDEA)中利用Maven进行混淆打包,确保代码的安全性并提高可维护性。 首先,让我们了解一下涉及的工具和技术: 1. **Java**: 一种广泛使用的面向对象的编程语言,用于构建跨...

    Java防编译技术---proguard混淆器

    Java防编译技术是开发过程中保护源代码安全性和技术保密性的重要手段,而ProGuard混淆器正是其中的关键工具。ProGuard是一款开源的Java字节码混淆、优化、压缩和预校验工具,它能帮助开发者有效地减少应用的体积,...

    maven 代码混淆.zip

    在Java开发领域,尤其是涉及到Android应用开发时,代码混淆是一...在Maven项目中,通过集成ProGuard或R8,并配置相应的混淆规则,可以实现代码的混淆处理。理解和掌握这些知识对于任何Java或Android开发者都是必要的。

    ProGuard工具包,Java代码混淆

    ProGuard作为Java和Android开发中的重要工具,不仅提供了代码混淆的安全保障,还带来了代码优化和压缩的性能提升。熟练掌握ProGuard的配置和使用,对于提升应用的安全性和性能具有显著作用。通过不断的实践和调整,...

    idfc-proguard混淆优化demo2

    【标题】"idfc-proguard混淆优化demo2" 涉及的是Android应用开发中的一个关键环节,即使用ProGuard工具进行代码混淆和优化。ProGuard是一个强大的Java字节码混淆、优化、预校验和分析工具,它可以减小APK的大小,...

    proguard-maven-plugin:支持模块化ProGuard软件包的ProGuard Maven插件

    **ProGuard Maven插件**是Java开发者在Maven构建流程中使用的一个重要工具,它主要负责执行代码混淆、优化、压缩和预校验等任务。这个插件是针对ProGuard工具的集成,使得在Maven项目中应用ProGuard变得更加便捷。...

    IDFC Maven ProGuard Plug-in:一个通过ProGuard混淆Java代码的Maven插件-开源

    该插件使您可以使用ProGuard开源混淆器来混淆Maven工件,ProGuard开源混淆器是一种非常强大且完善的Java混淆器。 也可以在SourceForge的http://proguard.sourceforge.net/上找到ProGuard。 可以从您的POM使用此插件...

    开发J2ME程序的混淆器proguard3.4

    2. **构建过程**:在构建过程中,将ProGuard集成到构建脚本中,如Ant或Maven,使得每次构建时都会自动执行混淆操作。 3. **测试混淆后代码**:混淆可能会影响程序的行为,因此混淆后需要进行全面测试,确保所有功能...

    java混淆代码的使用

    - 执行混淆:在构建脚本中添加混淆步骤,如在Gradle中使用`minifyEnabled true`开启混淆,并指定混淆配置文件。 - 测试混淆结果:混淆可能影响代码运行,因此混淆后需进行充分测试,确保功能不受影响。 5. **混淆...

    java源码混淆工具使用演示

    idea+maven+proguard,通过proguard实现源码的混淆编译,将源码的原始变量、方法名等按proguard规则进行统一修改替换,保证功能不变的情况下,一定程度提高源码的安全性,避免源码中的敏感词变量引起的安全检查异常...

Global site tag (gtag.js) - Google Analytics