喜歡用eclipse寫代碼,由於現在的eclipse配置導出的功能缺失較多。這裏開一帖把本人常用的配置記錄一番,省得再到處找。
另:工作空間中有個
.metadata
目錄保存了相關的插件及配置,可以複製到其他空工作間中複用配置。
設置工作空間字符編碼
Window-Preferences-General-Workspace-Text file encoding勾選Other與UTF-8
設置文件保存字符編碼
Window-Preferences-General-Content Types,選中需要的格式,在最下方Default encoding設爲UTF-8並Update
常用舉例:
Gradle Build Script、Java Class File、Text及Text下的Java Properties File(Java Properties File沒跟着父級Text指定字符編碼可能是bug,存在好多年了...)
設置jdk
Window-Preferences-Java-Installed JREs-Add-Standard VM-Next-Directory選中JDK目錄-Finish
回到了Installed JREs處,勾選剛添加的jdk目錄,Apply and Close
設置編譯器兼容性
Window-Preferences-Java-Compiler-Compiler compliance level選擇目前項目編譯的jdk版本,Apply and Close
設置maven
Window-Preferences-Maven-Installations-Add-Directory選中maven目錄-Finish,勾選剛添加的maven目錄,Apply and Close
修改Maven的源
編輯 maven目錄/conf/settings.xml
指定本地倉庫目錄位置(可選)
<localRepository>D:\MyTools\apache-maven-3.6.3\m2</localRepository>
指定鏡像源
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里雲公共倉庫</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>aliyunmaven</id>
<repositories>
<repository>
<id>aliyunmaven-jar</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyunmaven-plugin</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
設置gradle
Window-Preferences-Gradle-勾選 Local installation directory-Browse...-選擇gradle所在目錄-設置
Advanced Options的Gradle user home可選設置,會保存gradle緩存到該目錄中。
Apply and Close
設置Git默認克隆目錄
Window-Preferences-Team-Git-Default repository folder,直接輸入或者Browse..設置,Apply and Close
設置Java編輯器字體
Window-Preferences-General-Appearance-Colors and Fonts
設置基礎字體
Basic-Text Font
設置Java編輯器字體
Java-Java Editor Text Font
本人常用Source Code Pro 10號字
設置Java Properties編輯器字體
Java-Properties File Editor Text Font
設置Java編輯背景色(豆沙綠)
Window-Preferences-General-Editors-Text Editors-Appearance color options中的Backgroud color
點擊Color,在調色板上輸入:
紅199 綠237 藍204
添加到自定義顏色,選中該色,確定,Apply and Close
設置package explorer背景色(豆沙綠)
找到eclipse目錄下plugins/org.eclipse.ui.themes_1.2.1.v20170809-1435/css/e4_basestyle.css
不同的版本版本號不同。找到文件前綴爲org.eclipse.ui.themes的文件夾
在文件末尾添加如下代碼
#org-eclipse-jdt-ui-PackageExplorer Tree,
#org-eclipse-ui-navigator-ProjectExplorer Tree,
#org-eclipse-ui-views-ContentOutline Tree,
#PerspectiveSwitcher ToolBar {
background-color: RGB(199,237,204);
}
注:直接複製代碼,#別刪除。也可以放到e4_default_mac.css(mac)或e4_default_win.css (windows)文件。字體及大小也可以添加
設置console背景顏色(豆沙綠)
Window-Preferences-Run/Debug-Console-Background color,調色參考Java編輯器背景色部分。
設置空格縮進與折行長度
Window-Preferences-Java-Code Style-Formatter
New-輸入新格式化配置名,例MyProfile,以Eclipse [built-in] 初始化即可 -> OK
設置4空格縮進代替tab
在新彈出的窗體,展開Indentation,Tab policy設爲Space Only,默認tab size爲4就可以
設置註釋折行長度(格式化時註釋過長也會換行,可在此設置)
展開Comments, Maximum width for commends,默認80,按需調整
設置代碼折行長度(格式化時能需要換行的最小長度 或最大單行寬度)
展開Line Wrapping,Maximum line width設爲150(按需調整)
設置完成,點OK保存新格式配置,Apply and Close
設置輸入tab插入空格與刪除多個空格
Window-Preferences-General-Editors-Text Editors-勾選Insert spaces for tabs與Remove multiple spaces on backspace/delete
設置類型註釋模板
Window-Preferences-Java-Code Style-Code Templates-Comments-Types-Edit
/**
*
* @author Hellxz Zhang
* @date ${date}
*/
可以在其中插入一些需要的變量,這裏把當前操作系統的用戶名固定並設置日期
觸發此模板時可以直接定位到第二行輸入類的功能描述,比較方便。
Apply and Close,然後在類頭上輸入/**
+回車,即可觸發。
配置反編譯插件
看沒源碼的包怎能缺了它 :p,這裏使用 jd-gui的插件離線安裝
進入官方頁面 Java Decompiler (java-decompiler.github.io)
拖到 JD-Eclipse,點Download頁籤,點擊最新的Relase zip包 下載插件。例 jd-eclipse-2.0.0.zip
Installation
- Download JD-Eclipse ZIP file,
- Launch Eclipse,
- Click on "Help > Install New Software...",
- Drag and drop ZIP file on dialog windows,
- Check "Java Decompiler Eclipse Plug-in",
- Click on "Next" and "Finish" buttons,
- A warning dialog windows appear because "org.jd.ide.eclipse.plugin_x.y.z.jar" is not signed. Click on "Install anyway" button.
官方安裝教程如上所示,安裝完成後提示重啓eclipse生效。
重啓後還得設置一小下
Window-Preferences-General-Editors-File Associations,選中*.class without source
,點擊下方Associated editors右側Add,選中 JD Class File Viewer,OK
然後在Associated editors中選中JD Class File Viewer,點右側Default設爲默認,Apply and Close。
此時再打開沒源碼的類會有註釋的行號和最下方的反編譯信息,這個也可以去掉(不在意的可以不用往下配了)
Window-Preferences-Java-Decomplier取消勾選 Show original line numbers與Show metadata,Apply and Close即可。
無源碼的類中原本有的註釋不會被編譯到class中,所在有很多空行是正常的。