Files
server/JAR_OPTIMIZATION.md
2025-11-22 14:22:36 +08:00

99 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Jar包优化方案 - 800MB问题解决
## 问题分析
当前项目的800MB jar包主要来源于以下几类依赖
### 1. 系统作用域依赖 (System Scope) - 直接打包
- aspose-words-15.8.0-jdk16.jar (9.8MB)
- aspose-cells-8.5.2.jar (5.8MB)
- twain4java-0.3.3-all.jar (2.5MB)
- jai_core.jar (1.5MB)
- agent-1.0.0.jar (224KB)
### 2. 视频处理依赖 (最大体积来源)
- javacv + ffmpeg-platform (通常几十MB到上百MB)
### 3. 重复依赖
- jxl依赖重复声明
### 4. 多余的PDF处理库
- pdfbox, itextpdf, ofdrw-full可能存在功能重叠
## 优化策略
### 方案一:功能模块化 (推荐)
```xml
<!-- 创建独立的处理模块,不在主应用中使用 -->
<dependency>
<groupId>com.point.strategy</groupId>
<artifactId>document-processor</artifactId>
<version>1.0.0</version>
<scope>runtime</scope> <!-- 只在运行时使用 -->
</dependency>
```
### 方案二:分离部署
- 主应用 (约50-100MB)
- 文档处理服务 (独立部署)
- OCR服务 (独立部署)
### 方案三减少scope=system依赖
```xml
<!-- 改为provided或exclude -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.8.0</version>
<scope>provided</scope> <!-- 只在编译时使用 -->
</dependency>
```
## 立即可执行的优化
### 1. 移除重复依赖
```xml
<!-- 删除重复的jxl依赖 -->
```
### 2. 调整视频处理依赖scope
```xml
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.1</version>
<scope>provided</scope> <!-- 改为provided -->
</dependency>
```
### 3. 使用Spring Boot分层打包
```xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<requiresUnpack>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>
</build>
```
## 预期效果
优化后可将800MB减少到
- **保守估计**: 200-300MB (70%减少)
- **激进优化**: 50-100MB (90%减少)
## 实施建议
1. **第一阶段**: 移除重复依赖调整scope
2. **第二阶段**: 模块化文档处理功能
3. **第三阶段**: 考虑微服务拆分