本篇内容言简意赅,就算在座是智障程序员按照步骤也应该能成功。
1 追加支持库的仓库
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependencies>
2. 添加加密jar
<dependency> <groupId>com.github.core-lib</groupId> <artifactId>xjar</artifactId> <version>4.0.2</version> <!-- <scope>test</scope> --> </dependency>
public static void main1(String[] args) throws Exception { XCryptos.encryption() .from("/path/to/read/plaintext.jar") .use("io.xjar") .include("/io/xjar/**/*.class") .include("/mapper/**/*Mapper.xml") .exclude("/static/**/*") .exclude("/conf/*") .to("/path/to/save/encrypted.jar"); }
参数详解: https://github.com/core-lib/xjar
比如我的:
去除了 各种配置的静态资源,尤其是xml类的,否则会造成xml解析失败。从而提示如下错误:
Message: 前言中不允许有内容
在运行如上方法后就会在build下生成一个 xjar.go 的脚本。
这里需要安装go的环境。安装地址: https://studygolang.com/dl
安装完毕后,打开build目录,在地址栏里运行 cmd 打开dos窗口
然后运行脚本
go build xjar.go
执行结束后,会生成2个文件。
xjar.exe 和 encrypted.jar
encrypted.jar 就是加密后的jar,当你尝试反编译的时候 会出现:
当你想运行你的jar时,只需好执行脚本
xjar.exe java -jar encrypted.jar
即可正常运行。
本文结束。