基于xjar的springboot jar包加密方案

Published on 2023-12-04 16:17 in 分类: 随笔 with 狂盗一枝梅
分类: 随笔

环境准备:安装好go环境

xjar项目地址:https://github.com/core-lib/xjar

首先,引入xjar仓库源

<pluginRepositories>
    <pluginRepository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </pluginRepository>
</pluginRepositories>

然后,引入xjar插件

<plugin>
    <groupId>com.github.core-lib</groupId>
    <artifactId>xjar-maven-plugin</artifactId>
    <version>4.0.2</version>
    <executions>
        <execution>
            <goals>
                <goal>build</goal>
            </goals>
            <phase>package</phase>
            <!-- 或使用
            <phase>install</phase>
            -->
            <configuration>
                <password>io.xjar</password>
                <!-- optional
                <algorithm/>
                <keySize/>
                <ivSize/>
                <includes>
                    <include/>
                </includes>
                <excludes>
                    <exclude/>
                </excludes>
                <sourceDir/>
                <sourceJar/>
                <targetDir/>
                <targetJar/>
                -->
            </configuration>
        </execution>
    </executions>
</plugin>

执行mvn clean package命令,打包完成之后,查看target目录

image-20231204160626699

多出三个文件:.xjar、xjar.go、xjar_agentable.go

运行命令go build xjar.go,目录下会多出一个xjar.exe可执行文件,在当前打开命令行窗口,运行命令

xjar.exe java -Dfile.encoding=UTF-8 -jar xxx.xjar

或者git bash中运行

./xjar.exe java -Dfile.encoding=UTF-8 -jar xxx.xjar

即可

END.


#java #xjar #加密