ConfiguringEclipse

From HerzbubeWiki
Jump to: navigation, search

Contents

Overview

I use this page for writing down how I usually configure Eclipse when I am using it as an IDE.


Java specific configuration

Build Path

Go to Preferences -> Java -> Build Path:

  • Source and output folder = Folders
  • Source folder = src
  • Output folder name = bin


Compiler

Go to Preferences -> Java -> Compiler:

  • Compiler compliance level = 1.6
  • Task Tags
    • Case sensitive task tag names = false ("todo" and "TODO" comments should have the same effect)


Editor

Go to Preferences -> Java -> Editor:

  • Save Actions
    • Perform the selected actions on save = true
    • Format source code = true
      • Format all lines = true
    • Organize imports = true
    • Additional actions = true; click "Configure" to open a dialog which allows to change the following options
      • Code Organizing
        • Remove trailing whitespace = true
        • Correct indentation = true
      • Code Style
        • Use blocks in if/while/for/do statements = true
      • Unnecessary code
        • Remove unused imports


Javadoc

The following Javadoc settings (found under Preferences -> Java -> Compiler -> Javadoc) are very restrictive and create warnings if anything from the public interface is not properly and fully documented:

  • Process Javadoc comments = true
  • Malformed Javadoc comments = Warning
    • Only consider members as visible as = Public
    • Validate tag arguments = true
      • Report non visible references = true
      • Report deprecated references = true
    • Missing tag descriptions = Validate all standard tags
  • Missing Javadoc tags = Warning
    • Only consider members as visible as = Public
    • Ignore in overriding and implementing methods = true
  • Missing Javadoc comments = Warning
    • Only consider members as visible as = Public
    • Ignore in overriding and implementing methods = true


JREs

Go to Preferences -> Java -> Installed JREs:

    • Installed JREs
      • Checked JRE = JVM 1.6.0


C++ specific configuration

General Settings

Go to the "Preferences" dialog:

  • General
    • Editors
      • File Associations
        • Add "File Types" and "Associated Editors"
          • .pri / Text Editor
          • .pro / Text Editor
      • Text Editors
        • Undo history size = 1000 (default 200)
        • Displayed tab width = 2 (default 4)
        • Insert spaces for tabs = true (default false)
        • Show print margin = true (default false)
        • Show line numbers = true (default false)
      • Keys
        • See chapter about"Key Bindings"
    • Workspace
      • Save automatically before build = true
      • Text file encoding = UTF-8
      • Build Order
        • Here one can specify the build order of projects in case they have dependencies
  • C/C++
    • Appearance
      • Group include directives in Project Explorer and C/C++ Projects view = true
      • Group include directives in the Outline view = true
    • Build Variables
      • Add 2 new variables, both of type String
        • BUILDCOMMAND = nmake
        • BUILDVARIABLE = debug
    • Code Style
      • See chapter about "Code Style"
    • Indexer
      • See chapter about "Indexing"
    • New CDT project wizard
      • Makefile project (these settings will be used to create new projects, existing projects are left untouched)
        • Binary Parsers
          • Elf Parser = true
          • PE Window Parser = true
  • Team
    • SVN
      • See chapter about "Subclipse Configuration"


"Project Explorer View" context menu:

  • Top Level Elements = Working Sets


"Outline View" context menu:

  • Group Includes = true


"Console View":

  • Toggle button "Show Console When Standard Out Changes" = false
  • Toggle button "Show Console When Standard Error Changes" = false


Key Bindings

Go to "Preferences -> General -> Editors -> Keys":

  • Build All
    • Original Shortcut = Ctrl+B
    • New Shortcut = Ctrl+Alt+B
  • Build Project
    • Original Shortcut = None
    • New Shortcut = Ctrl+B (Original Command: "Build All")
  • Make Target Build
    • Original Shortcut = None
    • New Shortcut = Ctrl+T
  • Import (Import Wizard: Existing Projects into Workspace)
    • Original Shortcut = None
    • New Shortcut = Ctrl+I
  • Add Bookmark
    • Original Shortcut = None
    • New Shortcut = Ctrl+F2
  • Next Bookmark
    • Original Shortcut = None
    • New Shortcut = F2
  • Find Text in File
    • Original Shortcut = None
    • New Shortcut = Ctrl+F3


Doxygen Support

Go to "Preferences -> C/C++ -> Editor":

  • Documentation tool comments / Workspace default = Doxygen
    • I don't know what the exact effect of this setting is, but it at least triggers syntax coloring for Doxygen documentation blocks


Code completion

The indexing system must work for code completion to work. Getting the indexer to work properly is difficult if one is not using the gcc compiler. See chapter "Indexing" for details.


Code Style

The following documents the code style at Schiller AG, one of my previous work places.

Go to "Preferences -> C/C++ -> Code Style":

  • Click the "New..." button to create a new profile
    • Base the new profile on the built-in profile "GNU [built-in]"
  • Click the "Edit..." button and make the following changes
    • Indentation
      • Tab size = 2 (instead of 8)
    • Braces
      • Blocks = Next line (instead of "Next line indented")
      • Switch = Next line (instead of "Next line indented")


Exporting a code style:

  • Go to "Preferences -> C/C++ -> Code Style"
  • Select the style to be exported
  • Click the "Edit..." button
  • Click the "Export..." button


Importing a code style:

  • Go to "Preferences -> C/C++ -> Code Style"
  • Click the "Import..." button


Creating a new C++ project

The following steps work to create a project for the environment at one of my previous work places. In this environment we were using Qt's qmake to produce Makefiles on the different platforms, so we could not use the "Managed Makefile" project type. In addition, our projects were organized in a fixed folder structure, so we could not let them reside inside Eclipse's workspace.

Go to "File -> New -> C++ Project":

  • Project name = <name> (e.g. the name of the target inside the .pro file)
  • Use default location = false
    • Instead navigate to the project's root folder, i.e. the folder that contains the project's sources
    • Note: All files outside the selected root folder will later be inaccessible from the CDT's project explorer (even if they are being used for the build)
  • Project type = Makefile project/Empty project
  • Toolchain = -- Other Toolchain --
  • Click the "Finish" button


Configuring an existing C++ project

As above, the following steps work for the environment at one of my previous work places. On Windows we were using the MSVC toolchain, which means that on Windows the build utility is nmake.

Project Properties (Alt+Enter):

  • C/C++ Build
    • Builder Settings
      • Use default build command = false
      • Build command = ${BUILDCOMMAND} (this variable will be set in the Eclipse global settings; Windows = nmake, Linux = make)
    • Behaviour
      • Build (incremental build) = ${BUILDVARIABLE} (this variable will be set in the Eclipse global settings to either "debug" or "release")
    • Settings
      • Binary Parsers
        • Elf Parser = true
        • PE Windows Parser = true
        • this setting is important so that Eclipse is capable of detecting the build product (be it an executable or a library); I found this setting to be of importance for the "Run configuration..." dialog
        • in the Eclipse global configuration we will see that it is possible to make sure that these parsers are automatically added to the configuration of new projects

Project context menu (right-click on the project in the Project Explorer):

  • Make targets -> Create...
  • Target name = qmake
  • Use default = false
  • Build command = qmake
    • if the project contains multiple .pro files, the build command must be "qmake <name .pro file>"


Run configurations

Run configurations are used to launch applications that are built from Eclipse projects. A run configuration defines the environment that the application will be running in. This includes things such as:

  • The executable (e.g. an .exe file) that should be launched
  • Command line parameters
  • Environment variables
  • The debugger to be used
  • How should standard input/output be connected? By default the connection is made to the Eclipse's console view, but one could change this to e.g. a file


Before a run configuration can be created, Eclipse needs to be capable of recognizing the binaries produced by building a project (e.g. an .exe file). The reason for this is that Eclipse will let you choose the executable that it should run only from among known binaries, i.e. you cannot specify just any executable you would like. To let Eclipse recognize binaries as executables, the project must be configured with the appropriate "Binary Parsers". See the chapter about "Configuring an existing C++ project" for details.


To create a run configuration:

  • Select the project in the "Project Explorer"
  • Go to "Run -> Run Configurations..."
  • Right-click on "C/C++ Local Application", then select "New"
  • The executable to be run should be added automatically
  • If necessary, make further adjustments


Working Sets

Create a working set by going to "Project -> Build Working Set -> Select Working Set":

  • The dialog lets you manage working sets, i.e. create new ones, deleting them, renaming them, etc.
  • Click the "New..." button
  • Working Set Type = C/C++
  • Select the projects that are part of the working set (note that a project can be part of multiple working sets)
  • It is also possible to add single files instead of entire projects to a working set


Restrict a view (e.g. Project Explorer) to display only the content of certain working sets:

  • Open the view's context menu in the view's toolbar (triangle button on the toolbar's right)
  • Choose "Select Working Set..."
  • Choose the appropriate working sets
  • Note: Not all views support working sets


The "Window Working Set"

  • It is possible to define a so-called "Window Working Set" so that one does not need to configure multiple views over and over again with the same working sets
  • All views will be configured so that they only display the content of the Window working set
  • When the Window working set is changed, this immediately re-configured alls views
  • In my Eclipse installation I have so far not found a way how to configure the Window working set for the C++ perspective :-(


Indexing

Force indexing

Von sich aus indexiert CDT keines unserer Projekte. Die Indexierung *innerhalb* eines Projekts kann folgendermassen erzwungen werden:

   * Preferences -> C/C++ -> Indexer -> Index all files = true

Die Verknüpfung zu anderen Projekten (wichtig z.B. für Code Completion, und das Springen zu Klassen- und anderen Deklarationen) funktioniert ebenfalls nicht automatisch, da das automatische Feature "Path/Symbols Discovery" mit dem neuen VC9 Compiler (noch?) nicht funktioniert. Durch die manuelle Eingabe von Include Pfaden pro Projekt kann man sich behelfen, aber diese Pfade zu verwalten ist recht mühsam und ein gewisser Aufwand, der eigentlich nicht nötig wäre. Für Details siehe die Kapitel "Manuelle Eingabe von Include Pfaden" und "Path/Symbols Discovery" weiter unten.

Falls ein Index-Problem besteht, gibt es folgende Möglichkeiten, dem Problem auf den Grund zu gehen:

   * Kontext-Menü Projekt -> Index -> Search for unresolved includes
   * Kontext-Menü File (.h oder .cpp File) -> Index -> Create parser log file


Manuelle Eingabe von Include Pfaden

Damit der Indexer Verknüpfungen zwischen Projekten erkennt, kann man manuell Include Pfade pro Projekt definieren und damit die Abhängigkeiten festlegen.

   * Project Properties -> C/C++ General -> Paths and Symbols -> Includes

Nach einem Klick auf "Add..." erscheint ein Dialog, in dem man über den Button "Workspace..." zu dem Projekt innerhalb des Workspace navigieren kann, auf das man eine Abhängigkeit definieren möchte. Nach dem Bestätigen der Auswahl wird im Feld "Directory" der Workspace Pfad eingetragen und die Checkbox "Is a workspace path" ausgewählt. Beispiel: Wähle ich im Workspace das Projekt "SAF" aus, so wird der Workspace Pfad "/SAF" eingetragen.

Last but not least kann man noch die Checkboxes "Add to all configurations" und "Add to all languages" auswählen, damit die Abhängigkeit auf allen Ebenen vorhanden ist. Will man später einen Pfad ändern oder entfernen, muss man das natürlich in allen Konfigurationen und Sprachen tun.

Hat man alle Include Pfade gesetzt, sollte man um sicherzugehen den Indexer nochmals über das Projekt laufen lassen:

   * Kontext-Menü Projekt -> Index -> Rebuild


Path/Symbols Discovery

CDT scanned beim Builden eines Projekts den Build Output und versucht, Include/Library-Pfade und Symbole zu erkennen. Die erkannten Items werden dem Projekt automatisch hinzugefügt, was wiederum Einfluss auf das Indexing und damit auf alle möglichen auf dem Indexing basierenden Dienste hat (z.B. Code Completion, das Finden von Deklarationen, die Typen-Hierarchie oder der Include Browser). Die erkannten Items können eingesehen werden unter

   * Project Properties -> C/C++ General -> Paths and Symbols

Die Einstellungen, *wie* der Build Output gescanned werden soll und was genau mit den erkannten Pfaden und Symbolen gemacht werden, nennen sich "Discovery Options". Die Einstellungen werden pro Projekt verwaltet. Die initialen Werte werden dem Projekt beim Erstellen vom "New CDT project wizard" zugewiesen. Diese Default Einstellungen können geändert werden unter

   * Preferences Dialog -> C/C++ -> New CDT project wizard -> Makefile project -> Discovery Options

Einstellungen bei einem bestehenden Projekt können geändert werden unter

   * Project Properties -> C/C++ Build -> Discovery Options


VC9 Build Output kann nicht geparsed werden

CDT stellt verschiedene "Discovery Profiles" zur Verfügung, jedes dieser Profile stellt einen Scanner dar, der den Build Output anders parsed. Leider kann kein von CDT zur Verfügung gestellter Scanner den Build Output des VC9 Compilers erkennen. Die zur Verfügung stehenden Scanner können eingesehen werden unter

   * Preferences Dialog -> C/C++ -> New CDT project wizard -> Makefile project -> Discovery Options -> Discovery profile

Um das Problem zu umgehen, können manuell Include Directories definiert werden:

   * Project Properties -> C/C++ General -> Paths and Symbols
       * Wird auf ein Projekt innerhalb des Workspace verwiesen, kann ein Workspace Pfad hinzugefügt werden (z.B. /SCL/SCL_WIDGETS)
       * Bis jetzt habe ich es leider noch nicht geschafft, dass Eclipse Qt Includes erkennt (weder mit absoluter Pfadangabe, noch unter Verwendung von QTDIR)

Nach dem Hinzufügen von Include Directories muss der Index neu aufgebaut werden:

   * Kontext-Menü Projekt -> Index -> Rebuild


Resources zum Thema "Scanner Discovery"

http://download.eclipse.org/tools/cdt/docs/specs/Design_Specs/Scanner/scanner_config_fds.pdf

  • Dokument spezifiert, dass Compiler-spezifische Dinge via Extension Points generalisiert werden
  • gcc Spezialisierung wird durch das Implementieren der Extension Points erreicht
  • Scanner Discovery schlägt fehl, wenn kein Build Output vorhanden ist, weil z.B. der Build mit "make -s" (silent make) durchgeführt wird
  • Use Case "Discover compiler's intrinsic scanner info"
    • habe ich nicht ganz verstanden
    • im Fall von gcc lautet das Kommando
      • gcc -c -v target_specific_options {empty.c|empty.cpp}
    • es wird also ein leeres Pseudo-File kompiliert
    • die "target_specific_options" kommen durch das vorherige Parsen des Build Outputs zustande (Use Case "Discover scanner info")
    • es ist aber nicht ganz klar, welche Informationen der Aufruf generieren soll; der Use Case spricht hier von "specs output"
    • der Use Case wird durchgeführt, wenn sich die Optionen des Projekt-Targets ändern, also nicht bei einem Build selbst
  • gcc Extensions
    • GCCScannerInfoParser und GCCCompilerSpecsParser implementieren beide den Extension Point org.eclipse.cdt.core.ErrorParser
  • ein detektierter relativer Pfade muss entweder in einen absoluten, oder einen mit einer Variablen versehenen Pfad umgewandelt werden


https://bugs.eclipse.org/bugs/show_bug.cgi?id=236872

  • Implementation eines Scanners für Dwarf


http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.tools.cdt/msg07485.html

  • Thread mit ein bisschen Code zu einem Scanner für die MS VisualC++ tool chain


Subclipse

Konfiguration

Ohne spezielle Konfiguration in den Preferences verwendet Subclipse die gleiche Konfiguration wie TortoiseSVN und die standalone Subversion Installation. Auf meinem Laptop liegt diese z.B. im Pfad

C:\Dokumente und Einstellungen\dev\Anwendungsdaten\Subversion.


Konfiguration in den Preferences:

  • Team
    • Ignored Resources
      • Damit nicht generierte Verzeichnisse und Makefiles im Commit Dialog erscheinen, werden folgende Patterns definiert:
debug
release
Makefile
Makefile.Debug
Makefile.Release
*.vcproj
ui_*.h
  • SVN
    • Diff/Merge
      • Conflict Resolution Program = External
      • Path = C:\Programme\TortoiseSVN\bin\TortoiseMerge.exe
      • Parameters = /theirs:"${theirs}" /base:"${base}" /mine:"${yours}" /merged:"${merged}"


Nach der Installation

Nach der Installation müssen zuerst die verschiedenen Subversion Repositories konfiguriert werden. Dies geschieht in der View "SVN Repositories".

Als nächstes müssen die einzelnen Projekte mit den Repositories verknüpft werden. Dies geschieht in der View "Project Explorer":

  • Rechts Klick auf Projekt -> Team -> Share Project...
  • Repository Plugin = SVN
  • Auf der nächsten Seite des Wizards wird angezeigt, dass das Projekt bereits SVN Verzeichnisse enthält. Es wird ein Vorschlag gemacht, mit welchem Repository das Projekt verknüpft werden soll. Diesen Vorschlag kann man immer akzeptieren.


Arbeiten mit Subclipse

  • Informationen über die Datei oder das Verzeichnis in der Working Copy: Properties -> Subversion
  • Im Kontext Menü "Team" befinden sich folgende Subversion Operationen
    • Commit
    • Update
    • Branch/Tag
    • Merge
    • Switch
    • Log (unter dem Titel "Show History")
    • Properties
    • Revert
  • Im Kontext Menü "Compare with" sind die verschiedenen Möglichkeiten für ein Diff enthalten


Templates

Templates sind Code-Schnipsel, die schnell an der aktuellen Cursor-Position (z.B. mit dem Shortcut Ctrl+Space) eingefügt werden können. Templates sind in gewissen Grenzen parametrisierbar, so dass das Template beim Einfügen mit aktuellen Kontext-Informationen versehen wird.

Konfiguration im Preferences Dialog:

  • C/C++
    • Editor
      • Templates
        • Hier werden die Templates verwaltet
      • Content Assist
        • Advanced
          • Default Proposals Kinds
            • zusätzlich zum Default (Help und Parsing-based Proposals) kann hier Template Proposals ausgewählt werden (da man sonst mehrmals hintereinander Ctrl+Space drücken muss)


FAQ

Warum muss ich nach dem Anlegen eines neuen Workspace immer wieder alle Einstellungen (z.B. Key Bindings) neu machen?

Alle Einstellungen werden pro Workspace gespeichert. Es gibt verschiedene Lösungen für dieses Problem:

  1. Einen leeren Workspace anlegen und alle Einstellungen in diesem Workspace durchführen. Um einen neuen Workspace anzulegen wird einfach das Workspace Directory des leeren Workspace kopiert.
  2. Ein besserer Weg ist, die Preferences via Export/Import von einem Workspace in den anderen zu kopieren. Es können entweder alle Preferences, oder nur ein Teil (zur Zeit nur Key Bindings) kopiert werden.
  • Export: File -> Export -> General -> Preferences
  • Import: File -> Import -> General -> Preferences


Note: Es ist leider nicht möglich (oder ich kenne zumindest keinen Weg), Working Sets und importierte Projekte aus dem einen Workspace zu exportieren und in einen anderen (neuen) Workspace zu importieren.


Ich habe einen Compiler Fehler. Wie gelange ich am schnellsten von der Fehlermeldung in der Console in das File, wo der Fehler aufgetreten ist? Pendant in VC6: Doppelklick auf die Fehlermeldung, oder F8.

TODO


Gibt es ein Pendant zu Ctrl+F3 in VC6 ("suchen nach markiertem Text")?

Es gibt ein Command "Find Text in File", das Command kann sogar mit dem Shortcut Ctrl+F3 belegt werden, da dieser Shortcut sonst nicht verwendet wird.


Wie suche ich nach dem Gegenstück einer Klammer? (Shortcut in VC6 = Ctrl+E)

Ctrl+Shift+P, oder Navigate -> Go To -> Matching Bracket


Wie wechsle ich zwischen Header (.h) und Implementation (.cpp)? (Shortcut in VC6/VisualAssist = Alt+O)

Ctrl+Tab


Wie suche ich erneut nach dem letzten Suchbegriff, ohne das Suchfenster erneut zu öffnen? (Shortcut in VC6: F3)

Ctrl+K


Wo stelle ich ein, dass beim Starten eines Builds automatisch alle noch nicht gespeicherten Änderungen gespeichert werden?

Preference Dialog -> General -> Workspace -> Save automatically before build = true


Wie kann ich ein einzelnes File kompilieren? (Shortcut in VC6: Ctrl+F7)

TODO


Wie kann ich schnell für ein Projekt den qmake Schritt ausführen?

  1. Einen Shortcut für das Command "Make target build" definieren (z.B. Ctrl+T).
  2. Dieser Shortcut öffnet das Fenster mit allen definierten Targets
  3. Das "qmake" Target mit Cursor-Tasten auswählen, dann Enter drücken


Wie breche ich die Anwendung ab, die ich mit "Run..." oder "Debug..." gestartet habe (Shortcut in VC6: Shift+F5)

In der Console View gibt es einen roten, quadratischen Button, mit dem die laufende Applikation gestoppt werden kann. In der Debug Perspective ist das Command "Terminate" mit dem Shortcut Ctrl+F2 belegt. *Achtung:* Die Console View kann verschiedene Consoles anzeigen, es muss unter Umständen also diejenige Console in den Vordergrund geholt werden (mit Hilfe eines Buttons in der Console View Toolbar), die mit der laufenden Applikation verbunden ist. Dies kann vorkommen, wenn z.B. während dem die Applikation läuft ein Build gestartet wurde und deshalb die Build Console sich im Vordergrund befindet.


Wie erstelle ich ein Working Set?

Im gleichen Dialog, der der Auswahl eines Working Sets dient. Der Dialog ist an verschiedenen Orten zugänglich, z.B. im Kontext Menü der Project Explorer View.


Wie kann ich das Window Working Set definieren?

Gemäss Dokumentation sollte dies im Menü "Window -> Working Sets" möglich sein, dieses Menü existiert aber in meiner Eclipse Installation nirgends (bereits verschiedene Perspectives durchprobiert).

TODO


Ich habe ein Library-Projekt, für das ich eine Run Configuration definieren will, die ein Executable ausserhalb des Projekts startet (z.B. ein Unit Test Projekt, für das ich den Qt Test Runner starten will). Der "Run Configuration" Dialog erkennt das ausgewählte File aber nicht als Executable und disabled den "Run" Button. Was muss ich tun?

Für das Projekt müssen die korrekten Binary Parsers konfiguriert sein, damit das ausgewählte File als Executable erkannt wird. Diese Einstellung kann gemacht werden unter "Project Properties -> C/C++ Build -> Settings -> Binary Parsers". Zur Zeit werden die Parser "Elf Parser" und "PE Windows Parser" hinzugefügt.


Wie maximiere ich den aktuellen Editor oder die aktuelle View?

Ctrl+M, oder Window -> Navigation -> Maximize Active View or Editor.


Wie lege ich auf der Command Line fest, welchen Workspace Eclipse beim Start laden soll?

Die Option "-data" legt das Workspace Verzeichnis fest. Weitere Optionen sind dokumentiert unter http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.user/tasks/running_eclipse.htm


How do I configure Eclipse so that it warns me when I forget to put braces around single statement blocks?

This question arose while programming in Java. No answer found so far.

Instead of issuing a warning, Eclipe can be configured to automatically insert the missing braces when the file is saved. The relevant option is found under "Preferences -> Java -> Editor -> Save Actions -> Configure -> Code Style".


How do I configure the Java Formatter so that places a space after the unary operator !?

Preferences -> Java -> Code Style -> Formatter -> Edit -> White Space (tab) -> Expressions (tree element) -> Operators.

Here it is possible to check the option "after unary operators". The problem is that now the formatter will also put a space after the unary operator -, e.g.

int a = - 4;