Initial commit

This commit is contained in:
Docker7530
2026-03-01 01:43:46 +08:00
commit c6125c117b
3840 changed files with 415340 additions and 0 deletions
@@ -0,0 +1,34 @@
---
title: IDEA 2025.2 Maven中文乱码解决方案
created: 2025-08-06
source: Cherry Studio
tags: []
---
# IntelliJ IDEA 2025.2 中 Maven 控制台中文乱码终极解决方案
升级到 **IntelliJ IDEA 2025.2** 后,发现:**Maven 构建日志中的中文变成了乱码**。
## 问题原因
**IntelliJ IDEA 2025.2 开始**Maven 的执行方式发生了变化:
> **不再直接调用 `java.exe`,而是通过 `cmd.exe /c` 来启动 Maven**,可以从第一行看出来。
在中文版 Windows 系统中,`cmd.exe` 默认使用 **GBK 编码(代码页 936**,而项目和源码通常是 **UTF-8 编码**,这就导致了编码不一致,从而出现中文乱码。
即使你在项目中设置了:
- File Encoding 为 UTF-8
- Properties 中指定 `-Dfile.encoding=UTF-8`
也**可能无效**,因为 Maven 是通过 `cmd` 启动的,JVM 仍未强制使用 UTF-8。
## 解决方案:通过环境变量强制 UTF-8
我们可以通过设置 `JAVA_TOOL_OPTIONS` 环境变量,让 JVM **无论在哪种环境下都使用 UTF-8 编码**
1. 打开设置:`Ctrl + Alt + S` 或菜单 → File > Settings
2. 进入路径:Build, Execution, Deployment > Build Tools > Maven > Runner
3. 设置环境变量:Environment variablesName 为 `JAVA_TOOL_OPTIONS`Value 为 `-Dfile.encoding=UTF-8`
4. 保存并重启项目或 IDE