Skip to content

Eclipse

springside edited this page Oct 17, 2014 · 26 revisions

##1. 设置 每次新装Eclipse,都要设半天......可以设置好之后Export一个整体配置文件(File->Export->General->Preferences,Export All),以后直接Import这个文件。不过文件导出时又多又乱,需要排序,然后整理出修改过的部分。SpringSide整理了一个基于Eclipse 4.2(Juno) 的版本,在support/eclipse目录中。

###必选设置 1.Enable Save Action ,勾选自动格式化代码和整理Import
Java -> Editor -> Save Actions

2.设置智能内容辅助的热键
因为默认的热键原来是Ctrl+Space与输入法切换的热键冲突,Eclipse Juno默认为Alt+/,修改方法为General->Keys, 找到Content Assist,个人喜欢多加一个Shift + Space。

3.(手工)设置使用JDK 而不是 JRE, Java->Install JREs,选择JDK的目录为默认,否则看不到JDK自己的源码,而且Jetty编译JSP失败.

###可选设置 1.调整Java和XML的宽度到120
Java->Code Style->Formatter, 基于Eclipse-Buildin new 一个出来,设置Line Wrapping 和 Comments里的Line Width。
同时修改XML->XML Files->Editor。

2.设置JavaDoc格式
依然是Java->Code Style->Formatter,在new出来的profile中,Comments里, 勾选Never Join lines,取消 New Line after @param tags

3.import static org.junit.Assert.* 不会被解开成import static org.junit.Assert.Equal
修改Java->Code Style->Organize Import, 设置Number of static imports needed of * to 1.
单元测试中不愿意写Assert.equals()/Assert.isTrue(), 又不想一个个的import所有可能用到的assert函数时有用.

  1. assertThat()后自动提示引入org.assertj.core.api.Assertions.*
    修改Java->Editor->Content Assist->Favorites, new Member, 增加 org.assertj.core.api.Assertions.assertThat

5.设置Actions
Java -> Editor -> Save Actions,code style中勾选Use Blocks in if/while,钩选Convert For Loop to enhanced,钩选Use parenthese,取消Use Final Modifer where posibble。

6.设置代码Warning Java-> Compiler -> Errors/Warning

  • Code Style,选Parameter Assignment/Undocument empty block
  • Potential programming problems,选Possible boolean assignment/Empty Statement/Unused object alllocation/ Switch case fall through/ Missing synchronizied modifier on inherited method / Class override equals not hashcode
  • Name shadowing and conflicts, 全选剩下的两项。
  • Unnessary Code, 选Value of parameter is not use / Unnecessary cast or instanceof
  • Generic Type,全部取消。
  • Null analysis, 选potential null access/redudant null check

7.XML取消掉必须有DTD的warning,XML->XML Files->Validation,将No gammer specied改为Ignore.

8.(手工)设置Package Explorer展现,View Menu->Package presentation->Hierarchical.

9.(手工)设置Console, 取消Limit Console Output.

9.(手工)设置右下方的窗口,将用不上的窗口关掉,如properties, database exporler, snippets等。

##2. 插件

新版Eclipse的Eclipse Marketplace太好用了。下载安装插件及其依赖终于不是件太麻烦的事情,知道插件的名字,直接搜索然后安装就是了。

###2.1 M2Eclipse Maven插件终于成熟了,可以取代用mvn eclipse:eclipse生成项目。因为它可以在pom文件改变时自动装载Jar包,可以更好观察依赖关系,而且在Package View里那些Jar包不会密密麻麻的显示在外面。

在marketplace中搜索m2e, 插件有两个,一个是基本Maven Integration for Eclipse,另有一个Maven Integration for Eclipse WTP。我装了后者的最小组合,会自动装前者。

另外,因为Springside用到了maven的buildHelper项目添加functional test代码目录,在第一次打开项目时M2E会安装buildHelper plugin的connector。但是在这些额外代码目录里,如果要运行run main() 函数会出错,所以将QuickstartServer.java移回了src/test/java下。

原来用mvn eclipse:eclipse生成的项目文件必须完整删掉,否则m2e打开项目时会报classEntry=4 not support的错。

###2.2 EasyShell 在Eclipse左边的目录管理树里右键选easyshell,就可以打开文件夹,或者打开该目录下的dos shell窗口。

###2.3 SpringIDE 其实用途只是看application*.xml 文件时,写错类名会有提示,点中Class名会跳到相应的实现类。需要将所有applicationContxt-*.xml都加入其管理。安装最小的组合就行。

###2.4 其他编辑器 比如json、lua,都可以在Marketplace找到相应的编辑器。

##3. 运行调试Web应用。 Eclipse的Web应用runtime插件一般都需要复制整个Web Application内容到一个它的某个目录才能启动,而且对依赖项目的打包经常出问题。因此SpringSide选了用嵌入式的Jetty来就地启动。详见Jetty章节。

仿照在示例项目的test/java目录里的XXXXServer.java,复制一个到自己项目的测试目录,然后修改该文件指定项目web context path 及含有tld文件的jar包名称即可。