Eclipse 編碼設定分四層:Workspace → Project → Content Type → File,優先級遞增。亂碼本質是「檔案實際編碼」與「Eclipse 解碼編碼」不一致。
| 層級 | 設定路徑 | 適用範圍 |
|---|---|---|
| Workspace | Window → Preferences → General → Workspace → Text file encoding | 整個工作區新建檔案 |
| Project | 專案右鍵 → Properties → Resource → Text file encoding | 單一專案(覆蓋 Workspace) |
| Content Type | Preferences → General → Content Types → Text → Java Source File → Default encoding | 特定類型檔案(覆蓋 Project) |
| File | 檔案右鍵 → Properties → Resource → Text file encoding | 單一檔案(最高優先級) |
專案右鍵 → Properties → Resource → Text file encoding → Other → 選擇正確編碼(如 UTF-8/GBK)→ Apply
Preferences → General → Content Types → 選擇類型 → Default encoding 輸入正確編碼 → Update(必須點擊)
檔案右鍵 → Properties → Resource → Text file encoding → 修正
檢查系統是否安裝中文字體(微軟雅黑、宋體等),必要時重裝字體。
.settings/org.eclipse.core.resources.prefs 鎖定編碼pom.xml 設定 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>*.java text eol=lf 統一換行符