فهرست منبع

巧用loader.path

JustryDeng 3 سال پیش
والد
کامیت
ebb1cccd97
5فایلهای تغییر یافته به همراه139 افزوده شده و 6 حذف شده
  1. 139 6
      README.md
  2. BIN
      class-winter-core/src/test/resources/loaderpath测试源码.zip
  3. BIN
      file/1.png
  4. BIN
      file/2.png
  5. BIN
      file/3.png

+ 139 - 6
README.md

@@ -1,11 +1,12 @@
 # 代码混淆之class-winter
 
 - [代码混淆之class-winter](#代码混淆之class-winter)
-  - [<font  face="幼圆" color = "#3399EA" >功能与特性</font>](#font--face幼圆-color--3399ea-功能与特性font)
-  - [<font  face="幼圆" color = "#3399EA" >加密</font>](#font--face幼圆-color--3399ea-加密font)
-  - [<font  face="幼圆" color = "#3399EA" >加密参数</font>](#font--face幼圆-color--3399ea-加密参数font)
-  - [<font  face="幼圆" color = "#3399EA" >解密(启动)</font>](#font--face幼圆-color--3399ea-解密启动font)
-  - [<font  face="幼圆" color = "#3399EA" >解密参数</font>](#font--face幼圆-color--3399ea-解密参数font)
+  - [功能与特性](#功能与特性)
+  - [加密](#加密)
+  - [加密参数](#加密参数)
+  - [解密(启动)](#解密启动)
+  - [解密参数](#解密参数)
+  - [巧用loader.path](#巧用loaderpath)
 
 ---
 
@@ -321,4 +322,136 @@ linux示例:tips='请不要直接使用混淆后的jar/war'</td>
     <td>是否开启debug模式</td>
     <td>debug=true</td>
   </tr>
-</table>
+</table>
+
+## <font  face="幼圆" color = "#3399EA" >巧用loader.path</font>
+
+- 需求描述
+
+  已加密的包,如何提供给客户使用?
+
+  - 方案一:class-winter加密时,使用`alreadyProtectedLibs`参数,但是要求客户的的也想也需要使用class-winter加密(,哪怕客户的项目什么也不需要加密,也要求客户有使用class-winter这个动作)
+  - 方案二:-Dloader.path与class-winter结合使用
+
+- -Dloader.path方案实现
+
+  - 假设客户依赖了我们的加密包
+
+    ![客户项目](./file/1.png)
+
+  - 客户使用maven插件,打包时将项目代码和以来的lib分开
+
+    完整pom示例:
+
+    ```xml
+    <?xml version="1.0" encoding="UTF-8"?>
+    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+        <modelVersion>4.0.0</modelVersion>
+        <parent>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-parent</artifactId>
+            <version>2.6.4</version>
+            <relativePath/> <!-- lookup parent from repository -->
+        </parent>
+        <groupId>com.example</groupId>
+        <artifactId>demo</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <name>demo</name>
+        <description>Demo project for Spring Boot</description>
+        <properties>
+            <java.version>1.8</java.version>
+        </properties>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-web</artifactId>
+            </dependency>
+    
+            <dependency>
+                <groupId>org.projectlombok</groupId>
+                <artifactId>lombok</artifactId>
+                <optional>true</optional>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-test</artifactId>
+                <scope>test</scope>
+            </dependency>
+    
+            <dependency>
+                <groupId>com.demo</groupId>
+                <artifactId>encrypted-lib-no-pwd</artifactId>
+                <scope>system</scope>
+                <version>1.0.0</version>
+                <systemPath>${pom.basedir}/src/main/resources/lib/encrypted-lib-no-pwd-1.0.0.jar</systemPath>
+            </dependency>
+        </dependencies>
+    
+        <build>
+            <plugins>
+                <plugin>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-maven-plugin</artifactId>
+                    <configuration>
+                        <!-- 指定该Main Class为全局的唯一入口 -->
+                        <mainClass>com.ideaaedi.demo.DemoApplication</mainClass>
+                        <!-- 把systemPath指定的jar包也纳入lib -->
+                        <includeSystemScope>true</includeSystemScope>
+                        <fork>true</fork>
+                        <!-- 设置为ZIP,此模式下spring-boot-maven-plugin会将MANIFEST.MF文件中的Main-Class设置为org.springframework.boot.loader.PropertiesLauncher -->
+                        <layout>ZIP</layout>
+                        <includes>
+                            <include>
+                                <groupId>nothing</groupId>
+                                <artifactId>nothing</artifactId>
+                            </include>
+                        </includes>
+                    </configuration>
+                    <executions>
+                        <execution>
+                            <goals>
+                                <goal>repackage</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+    
+                <!-- 通过插件将所有依赖的lib包放到编译后的target/lib目录,并且在打包时候排除内部依赖 -->
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-dependency-plugin</artifactId>
+                    <version>3.2.0</version>
+                    <executions>
+                        <execution>
+                            <id>copy-dependencies</id>
+                            <phase>prepare-package</phase>
+                            <goals>
+                                <goal>copy-dependencies</goal>
+                            </goals>
+                            <configuration>
+                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                                <overWriteReleases>false</overWriteReleases>
+                                <overWriteSnapshots>false</overWriteSnapshots>
+                                <overWriteIfNewer>true</overWriteIfNewer>
+                                <includeScope>compile</includeScope>
+                            </configuration>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </build>
+    
+    </project>
+    ```
+
+    打出来的包:
+
+    ![打出来的包](./file/2.png)
+
+  - 客户可以这样启动项目
+
+    > `java -Dloader.path=./lib/ -javaagent:./{class-winter.jar} -jar {客户项目.jar}`
+
+    ![使用loader.path引入依赖](./file/3.png)
+

BIN
class-winter-core/src/test/resources/loaderpath测试源码.zip


BIN
file/1.png


BIN
file/2.png


BIN
file/3.png