1、为什么要使用Eclipse?
eclipse作为免费的开发ide软件,使用起来不会存在法律问题
eclipse系统占用资源小于idea
eclipse开发起来效率高于idea,不像idea会很容易出现因为切换分支而导致maven依赖错乱的问题
debug调试方便,即使其他服务有编译报错的也不会影响当前服务编译启动
2、如何安装配置eclipse java开发环境
以eclipse 2024为例。为什么不使用老版本?因为有些老版本插件市场不再进行支持。
- 到官网 https://www.eclipse.org/downloads/ 下载eclipse2024版本
- 因为eclipse2024运行环境需要jdk17
- 安装时选择Enterprise Java and Web developers
- 配置eclipse.ini 文件避免jdk冲突导致启动闪退,加入配置:
-vm
D:/jdk17/bin/java.exe(填自己jdk17的路径) - 配置maven, window->preferences->installations和
window->preferences->User Settings - 配置字体大小, General->Appearance->color and fonts
- 配置编码
Preference → General → Workspae Text file encoding修改为UTF-8;
Preference → General → Content Types 选择Text在下面发Default encoding中输入UTF-8然后点update;
Preference → General → Content Types 展开Text选项,选择Java Properties File将默认的ISO-8859-1改为UTF-8然后update;
Preference → Web—>JSP Files 将encoding修改为UTF-8。
- 设置换行符风格
Preference → General → Workspae New text file line delimiter修改为Unix;
- 设置缩进方式
Preference → General → Text Editors → Insert spaces for tabs 不勾选;
-
设置JDK
Preference → Java → Installed JREs 中添加JDK(需要JDK1.8_211版本), 设置使用JDK 而不是 JRE,并且将JDK设置为默认;
-
设置快捷键
若默认的Ctrl+Space与输入法切换的热键冲突,需要修改下快捷键(修改eclipse或者输入法切换键二者之一);
设置代码Format格式-
调整Java和XML的宽度为150;
Java → Code Style → Formatter, 基于Eclipse[built-in] new 一个出来(name为qiyuesuo),设置Line Wrapping 和 Comments里的Line Width。
同时修改XML → XML Files → Editor 里面的line width; -
设置JavaDoc格式
Java → Code Style → Formatter,在new出来的qiyuesuo中,Comments里, 勾选Never Join lines; -
设置Actions
Java → Editor → Save Actions,勾选Perform the selected actions on save,勾选选项下面的 Organize imports和Additional actions;
Additional actions打开configure配置项,在code style中勾选Use Blocks in if/while,Convert For Loop to enhanced。
4.设置去除import * (必须)
Java → Code Style → Organize Import 将Number of imports needed for .* 改成99
将Number of static imports needed for .* 改成99
5.设置imports的排序(必须)
Java → Code Style → Organize Import
删除 org和com
新增 * (all unmatched type imports)
新增 * (all unmatched static imports) 并重新排序。
最终顺序如图:
-
-
代码编译设置
该项配置在Preference → Java → Compiler下;
- 设置java编译级别为1.8;
- 设置代码Warning,Java → Compiler → Errors/Warning
Code Style:默认;
Potential programming problems:将‘switch’is missiong default改为Warning,其他默认;
Name shadowing and conflicts:全部为Warning。
Unnessary Code:增加Unnecessary ‘else’ statement为Warning,其他为默认;
Generic Type:Generic type parameter declared这项为Warning,其他设置为Ignore;
Annottion:全部设置为Warning;
Null analysis:默认不变。
-
修改Validation
- Preference → Validation中,Build列只保留HTML Validation,JSP Validation和XML Validation,其他的均取消;
- XML取消掉必须有DTD的warning,XML → XML Files → Validation,将No gammer specied改为Ignore.
-
其他配置
- Git设置:Team → Git → Label Decorations 在右侧的Icon Decorations面板中勾选Dirty resources选项
-
配置语法提示,Editor →Content Assist,以及提示优先级
-
配置xml sql语法提示,Eclipse配置MyBatis的xml自动提示_eclipse mybatis xml 无提示-CSDN博客
安装如下插件
SonarInt