引言

为了保密需要,我们开发出来的程序在实际部署之前,需要先将jar包的代码进行混淆,让用户使用反编译也无法获得源码。

allatori就是这样一个混淆java jar包代码的工具。

操作步骤

Step1.在pom中添加插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-and-filter-allatori-config</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/allatori</directory>
<includes>
<include>allatori.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run-allatori</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xms128m</argument>
<argument>-Xmx512m</argument>
<argument>-jar</argument>
<argument>${basedir}/lib/allatori.jar</argument>
<argument>${basedir}/lib/allatori.xml</argument>
</arguments>
</configuration>
</plugin>

Step2.copy jar包到插件里配置的路径

Step3.编写配置文件,并放在插件里配置的路径下

示例配置:

  • 配置中最重要的的配置是<jar in ="xxx" out="xxx"/><ignore-classes>

    • 第一个标签用来指定将什么包混淆,混淆后的输出包名是什么
    • 第二个标签用来指定什么包、类不进行混淆。注意,主类不要进行混淆,其他第三方jar包的代码不要进行混淆(否则会出现java.lang.NoClassDefFoundError错误)。
<config>
<input>
<!-- in表示输出的原始jar包,out表示输出的混淆后的jar包,后者名称可自定义,也可以是war -->
<jar in="../target/akkaload-core-0.0.1-SNAPSHOT.jar"
out="../target/akkaload-core-0.0.1-SNAPSHOT.jar"/>
</input>
<keep-names>
<class access="protected+">
<field access="protected+"/>
<method access="protected+"/>
</class>
</keep-names> <property name="log-file" value="log.xml"/> <!-- 忽略的包或类,这些文件将不被混淆 -->
<ignore-classes>
<!-- 不要混淆主类 -->
<class template="class com.navi.akkaload.AkkaloadApplication" />
<!-- 不要混淆第三方的代码,否则会运行jar包会报错java.lang.NoClassDefFoundError -->
<class template="class org.dom4j.*" />
<class template="class akka.actor.*" />
<class template="class *alibaba*" />
<class template="class *org*" />
<class template="class *rabbitmq*" />
<class template="class *springframework*" />
<class template="class *lombok*" />
</ignore-classes> <!-- 到期时间(到期后无法启动jar) 格式:yyyy/mm/dd-->
<!--<expiry date="2021/04/03" string="SERVICE EXPIRED!"/>-->
<!-- 随机命名混淆字符-->
<!--<property name="random-seed" value="abcdef ghnljk svi"/>--> </config>

效果

打开混淆成功后的jar包,会发现代码已经被混淆。

最新文章

  1. Daily Scrum Meeting ——FourthDay(Beta)12.12
  2. 添加native service
  3. handler和Timer的用法
  4. [译]2016年深度学习的主要进展(译自:The Major Advancements in Deep Learning in 2016)
  5. python数字图像处理(16):霍夫圆和椭圆变换
  6. JS模块规范 前端模块管理器
  7. csc.rsp Invent by Microshaoft
  8. 解决(空密码的root)提示修改phpmyadmin用户密码
  9. c# 文件夾操作
  10. 微信公众平台 Premature end of file
  11. DecimalFormat用法
  12. 变量值a交换b,b交换a....
  13. koa-ueditor上传图片到七牛
  14. ABP给WebApi添加SwaggerUI,生成可交互接口文档
  15. USACO 4.3 Street Race
  16. WampServer -- “You don&#39;t have permission to access /phpmyadmin/ on this server.”
  17. caffe读取多标签的lmdb数据
  18. Android内存优化10 内存泄漏常见情况1 静态泄漏
  19. DbUtils(二) 结果集实例
  20. [转]理解Object.assign

热门文章

  1. python 常用内置函数简介
  2. 一个&quot;.java&quot;源文件中是否可以包括多个类(不是内部类)?有什么限制?
  3. Spring-boot-菜鸟-properties配置
  4. memcached 最大能存储多大的单个 item?
  5. PowerDesigner生成MySQL脚本,表和字段进行转义
  6. Servlet与JSP之间相互传值问题
  7. AOP——基于AspectJ的注解来实现AOP操作
  8. 学习Apache(三)
  9. c语言代码规范
  10. 解决使用 swiper 常见的问题