Skip to content
renepickhardt edited this page Mar 11, 2014 · 12 revisions

Eclipse

Guide created on 6th March 2014 with Eclipse Version 4.3.1.

If you have trouble following the introductions, make sure your Eclipse is up to date.

Plugin Installation

General

Plugins can be installed in 3 Different ways:

  • Your Distributions Package Manager

    This is the preferred way. To check if your distro hosts a package for the plugin do a simple search with your distros package manager (e.g. search for "eclipse maven").

  • Eclise Marketplace

    The easiest way to install new plugins. Open the Marketplace (Help -> Marketplace), search for your plugin, and hit install.

    The Marketplace might not be available in your Eclipse installation. To install it:

    1. Help -> Install new Software...
    2. Select All Available Site in the Work with drop-down menu.
    3. Wait for the list of software to populate; sometimes it takes a very long time.
    4. Expand the General Purpose Tools group, and tick Marketplace Client.
    5. Click Next, accept the terms and conditions and click Finish.
  • Update site

    This way should work for all plugins and distros.

    1. Help -> Install new Software...
    2. Click Add... in top right
    3. Paste Plugin Update Site into Location, click Ok.
    4. Select plugins you want to install, hit Next, accept terms and conditions and click Finish.

Plugins

Import code into new project

  1. Checkout the source code, for example:
  • git clone https://github.com/renepickhardt/metalcon.git
  • git checkout feature/middleware
  1. Start a new Project: File -> New -> Java Project
  • Uncheck Use default location
  • Browse to source directory.
  • Click Next and Finish until done.
  1. If the code is built with Maven (most likely is)

Right-click Project -> Configure -> Convert to Maven Project

  1. If you wish* to use Git Integration

Right-click Project -> Team -> Share Project -> Use Parent Folder

Settings

  • You can download preconfigured eclipse project settings containing our coding style. Download this archive extract it and place the folder it contains and place it into your project directory (careful its called .settings so its a hidden folder under linux).

  • Hierarchical packages

    Click downward triangle in top-left of Package Explorer -> Package Representation -> Hierarchical

    Greatly helps with browsing large code bases, as packages are no longer listed flat, but the hierarchical structure can easily be understood.

  • Window -> Preferences

    • General -> Editors -> Text Editors

      • Set Display tab width to 4.

        4 characters deep indentation is standard in the Java world.

      • Check Insert spaces for tabs.

        Spaces for tabs is the only way to have consistent indentation across multiple platforms.

      • Check Show print margin, and set Print margin column to 80.

        Limiting line width to 80, enables side by side code comparison, and allows to work with small monitors. For a discussion on this topic see: Stackoverflow: Is there valid reason for enforcing a maximum width of 80 characters?

      • Check Show line numbers.

    • General -> Workspace

      • Check Text file encoding to be UTF-8.

      • Check New text file line delimiter to be Unix.

        UTF-8 and Unix newlines are project standards. These settings are required for you to not mess up the code base.

    • Java -> Editor -> Folding

      • Check Enable Folding.

        Allows you to fold code sections or comments to have an easier overview over your code.

    • Maven

      • Check Download Artifact JavaDoc.

        Makes sure JavaDoc works for maven dependencies.

      • Maven -> User Interface

        • Check Open XML page in the POM editor by default.

          If you editor your pom.xml in Eclipse you might prefer this settings, as I find the standard Maven Pom-Overview to be useless.

    • XML -> XML Files -> Editor

      • Set line width to 80.
      • Check indent using spaces.
  • Set up your settings according to the Metalcon-StyleGuide.

Usage

  • Code completion for most languages while editing Code with Ctrl+Space
  • Multiple Editor panes
    • Drag Code editors or files into different panes for side by side viewing.
    • Duplicate Editor with Window -> New Editor.
  • Hovering over an Identifier for some time gives JavaDoc-Tooltip (or F2)
  • Ctrl+Click over an Identifier takes you to definition (or F3)
  • Rightclick on an error indicated by eclipse in your code, opens quickfix, a list of probable fixes.

Useful Shorts-cuts

  • Alt+Up/Down-Arrow - Move selected code up/down.
  • Ctrl+1 - Quickfix
  • Ctrl+Shift+R - Open Resource
  • Ctrl+Shift+T - Open Type

Code editing

  • Right-click -> Source
    • Indent selected lines with Tab, unindent with Shift+Tab.
    • (Un-) Comment selected lines (Ctrl+Shift+C or Strg+/).
    • Generate Getters and Setters
  • Right-click -> Refactor
    • Rename any identifier (Alt+Shift+R)
    • Move a class to another location (Drag & Drop in Package Explorer or Ctrl+Alt+V)

Debugging

  • Click on right border with line numbers -> Toggle Breakpoint
  • Execute Debug Run (F11)
  • Allows to see current variable values.
  • Allows to do step-by-step execution.
  • Allows to follow program path.

Maven Plugin

  • When changing something Maven related (for example, editing pom.xml): Right-click Project -> Maven -> Update Project (or Alt+F5).
  • Run Maven build from Eclipse: Right-click Project -> Run As -> Maven ....

Git Plugin

  • Little yellow icon in bottom left of file icon tells us this file is stored in git repository.
  • A ">" in front of a file name indicates a not-yet-committed file change.
  • Git related stuff are best done on command line for better overview (pushing, pulling, etc.)
  • Actually useful features:
    • Right-click on anything (project or file) -> Team -> Show In History
    • Right-click on files in history ->
      • Compare with Workspace
      • Compare with Version in Ancestor
      • Show annotations (can be clicked)
Clone this wiki locally