来访~103015 文章~106 评论~25
2024年3月29日 作者 张临志

jeecgboot使用allatori混淆打包后台

熟悉Java的人都知道Java代码编译成class文件就可以部署运行了,但是class文件通过jdk-gui等工具是很容易反编译就看到源代码的,在代码给到客户私有化部署时,为了保护咱们自己的知识产权,我们会使用加密、花指令、混淆等方式对代码进行保护。

jeecgboot使用maven打包后的jar包存放在jeecg-module-system\jeecg-system-start\target目录下,本文档使用allatori对打包完成的jar包进行二次混淆。

首先在jeecg-module-system\jeecg-system-start根目录新建allatori文件夹其中新建allatori.xml文件及lib文件夹,lib文件夹下面放置allatori.jar和allatori-annotations.jar

其中allatori.xml内容如下:

<config>
    <input>
        <jar in="jeecg-system-start-3.6.3.jar" out="jeecg-system-start.jar"/>
    </input>

    <keep-names>
        <!-- protected/public的都保留名称 -->
        <class access="protected+">
            <field access="protected+" />
            <method access="protected+" />
        </class>
    </keep-names>
    <ignore-classes>
        <!-- 注意:spring的框架相关的文件需要排除,避免启动报错 -->
        <class template="class *springframework*"/>
    </ignore-classes>

    <property name="log-file" value="log.xml"/>
</config>
最后修改jeecg-module-system\jeecg-system-start下面的pom.xml,添加如下:
<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>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>allatori/lib/allatori.jar</argument>
            <argument>${basedir}/target/allatori.xml</argument>
        </arguments>
    </configuration>
</plugin>
Allatori官网