Files
Knowledge/1 使用/maven/Maven 编译报错乱码.md
T

11 lines
959 B
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.
在 IDEA 中为 Maven 设置 `JAVA_TOOL_OPTIONS` 环境变量,强制 JVM 使用 UTF-8 编码[-5](https://juejin.cn/post/7576518316135759923)[-7](https://blog.csdn.net/vistaed/article/details/160566415)。这个方法对 IDEA 2025.2+ 版本最有效,只需设置一次,全局生效[-11](https://blog.csdn.net/m0_55762904/article/details/153689615)。
1. 打开 IDEA 设置 (`Ctrl + Alt + S`)。
2. 导航到 `Build, Execution, Deployment` → `Build Tools` → `Maven` → `Runner`。
3. 找到 **`Environment variables`** 字段,点击右侧的文件夹图标或输入框[-7](https://blog.csdn.net/vistaed/article/details/160566415)。
4. 添加环境变量,设置 `Name` 为 `JAVA_TOOL_OPTIONS`,`Value` 为 `-Dfile.encoding=UTF-8`[-5](https://juejin.cn/post/7576518316135759923)[-7](https://blog.csdn.net/vistaed/article/details/160566415)。
5. 点击 `OK` 保存设置,然后重新执行 Maven 编译。