Window → Preferences → General → Workspace
→ Text file encoding: Other → UTF-8
→ New text file line delimiter: Unix (LF) 推薦

注意:僅對**新建立**的專案生效,既有專案不受影響。
Window → Preferences → General → Content Types
→ Text → Java Source File (或 JSP, XML, Properties, CSS, JS 等)
→ Default encoding: UTF-8 → Update

專案右鍵 → Properties → Resource
→ Text file encoding: Other → UTF-8
此設定儲存於專案目錄 `.settings/org.eclipse.core.resources.prefs`,提交版控可共享給團隊。
檔案右鍵 → Properties → Resource
→ Text file encoding: Other → UTF-8
Run → Run Configurations → Common → Encoding: UTF-8
或
-Dfile.encoding=UTF-8 (VM Arguments)
<!-- pom.xml -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
// build.gradle
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
compileJava.options.encoding = 'UTF-8'
| 現象 | 可能原因 | 解決 |
|---|---|---|
| 主控台輸出亂碼 | Run Configuration 編碼非 UTF-8 | 設定 Common → Encoding: UTF-8 |
| JSP 頁面中文亂碼 | JSP 指令缺失或 Tomcat URIEncoding | `<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>` + `server.xml URIEncoding="UTF-8"` |
| 資料庫中文亂碼 | 連線字串無 characterEncoding | JDBC URL: `?characterEncoding=utf8&useUnicode=true` |
| Git 提交檔案編碼不一 | 缺 `.gitattributes` | 加入 `* text=auto eol=lf` 或 `*.java text eol=lf` |
| Properties 檔中文變 \uXXXX | Java 標準為 ISO-8859-1 | IDE 設定 UTF-8 並啟用「透明轉換」,或用 YAML/JSON 替代 |