如何记录自用Eclipse配置以备后续快速查找?

摘要:![](https:img2023.cnblogs.comblog11493982023081149398-20230830174217779-860426629.png) > 喜欢用eclipse写代码,
喜欢用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中,所在有很多空行是正常的。