Eclipse 使用点滴

1. import 包引用自动添加

  • Ctrl + Shift + o

2. 代码风格改为 C++ 风格

  1. 菜单栏:Window –> Preference;
  2. treepane:Java –> Code Style –> Formatter,编辑一个具体的 profile即可。

3. 添加代码自动提示

  • Java文件自动提示
  1. 菜单栏:Window –> Preference;
  2. treepane:Java –> Editor –> Content Assist,找到 Auto-Activation ,找到 “Auto activation triggers for Java:” 选项,把该文本框中的 . 换掉,换成abcdefghijklmnopqrstuvwxyz.
  • XML文件自动提示
  1. 菜单栏:Window –> Preference;
  2. treepane:XML –> XML Files –> Editor –> Content Assist,找到 “Auto activation” 选项,在 “Prompt when these characters are inserted” 中,默认设置为 <=: ,将其改为 <=:.abcdefghijklmnopqrstuvwxyz(

4. 代码格式自动调整

  • Ctrl + Shift + f

5. eclipse 插件安装

eclipse 插件安装方式有多种。

使用link链接安装法,插件卸载比较灵活,重点介绍link 链接插件安装法。

在 eclipse 安装文件夹分别建立 PluginEclipse 文件夹(这个可以任意取名)和 links 文件夹。

  • PluginEclipse 文件夹拷贝插件文件,拷贝路径为: ..\PluginEclipse\插件名称\eclipse\,拷贝文件为 features 文件夹和 plugins 文件夹。
  • links 文件夹用于存放插件的链接路径,在 links 文件夹下建立文件:插件名称.link,编辑该文件内容为:
    path=C:\\eclipse\\PluginEclipse\\插件名称 或
    path=C:/eclipse/PluginEclipse/插件名称

    安装完成,重启 eclipse,在 about 中 installation Details 中查看插件安装情况。

6. workplace 配置共享

eclipse不同workplace配置各不相同,在workplace中的配置无法自动导入另一个workplace。使用下述方法在各个workplace之间共享配置。

  1. Go to ${old_workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings.
  2. Copy everything under the above directory to
    ${new_workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings.

7. eclipse界面定制

eclipse作为著名开源IDE,为用户提供了绝对的灵活性,界面当然也是可定制的。

eclipse的界面元素设置在文件夹中eclipse/plugins/org.eclipse.platform_4.2.*/css/中,针对不同的 OS 平台有不同的文件进行界面风格设定。不同的 OS 平台,只要修改对应的 css 文件,即可改变 eclipse 在本平台的显示风格。

  • 隐藏状态栏
    #org-eclipse-ui-trim-status, 
    #org-eclipse-ui-trim-vertical1, 
    #org-eclipse-ui-trim-vertical2 
    { 
        visibility: hidden; 
    }
    
  • 设置 tab 页
    .MPartStack 
    { 
        font-size: 9; 
        font-family: Liberation Sans; 
        swt-tab-renderer: null; 
        swt-tab-height: 22px; 
        swt-selected-tabs-background: #FFFFFF #ECE9D8 100%; 
        swt-simple: false; 
        swt-mru-visible: false; 
    }
    

更多信息参见eclipse官网的介绍。

8. 配置工具栏按钮

  • 菜单栏:window –> Customize Perspective…

9. 在 windows 平台与 linux 平台间转换程序

虽然 java 具有良好的跨平台特性,但将 windows 下程序转移至 java 下如不进行正确调整,仍会存在许多问题。

  1. java.lang.NoClassDefFoundError 错误

    to fix this you need to make sure your Run Configurations are set up correctly. To do this, go to Run > Run Configurations…. Once there, find the failing Run Configuration in the menu on the left. Choose the Plug-ins tab just below the box to enter the run configuration’s name. In the text box which says “type filter text”, type swt and check any unchecked boxes.

  2. 文件字体编码问题

    • 为 eclipse 添加 gbk 支持

      windows 下 eclipse 默认使用 gbk 编码,而 linux 下则默认使用 utf-8 编码,windows 下程序迁移至 linux 下需在 linux 中设置 gbk 支持,可参见如下信息:

      • http://www.cxyclub.cn/n/29193/
      • http://www.2cto.com/os/201506/405438.html
    • 统一设置 UTF-8 编码
      • http://www.blogjava.net/xiaomage234/archive/2014/05/13/413626.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注