Contents:

Introduction

Eclipse is a multi-platform integrated development environment with strong support for Java. In addition to various features that facilitate the writing of Java code (such as autocompletion and code refactoring), it has built-in support for CVS, JUnit, and Ant — tools that we use in 6.170.

Eclipse (version 3.2M4) is already installed on Athena. If you wish to use it at home, you need to download Eclipse 3.2.1. If you use an earlier version, it may have poor support for generics and other Java 5 features, and you will not be able to use the Continuous Testing plug-in.)

You can read more about and get help on the features of Eclipse in its online documentation. You can download version 3.2M4 (the version we have configured Athena to run this semester) here.

(Note for Microsoft Windows users. Unlike some other software packaged for Windows, there is no "installer" file to execute for Eclipse. Instead, extract the contents of the zip file into a directory and directly run the file eclipse.exe to start Eclipse.)

Eclipse Quick Reference

Related pages:

Here are some tips for things that can make your life easier in Eclipse:

Autocomplete Ctrl-Space asks Eclipse to help you complete some code you've started.  Eclipse can complete lots of things:
  • variables, method names, class names
    • ArrayL Ctrl-Space    -->  ArrayList
    • random.next  Ctrl-Space  -->  random.nextInt
  • constructor and method parameters
    • new ArrayList(    Ctrl-Space  --> popup menu of ArrayList's constructors
    • random.nextInt(   Ctrl-Space --> tooltip showing nextInt's parameters
  • methods to override
    • class Foo extends Bar {    Ctrl-Space --> menu of Bar's methods that can be overridden
Organize import statements Ctrl-Shift-O (that's O as in Organize) automatically updates the import statements at the top of your class, adding classes that need to be imported from other packages and removing classes that you're no longer using.  If a class name is ambiguous -- e.g., List might be either java.util.List and java.awt.List -- then Eclipse pops up a dialog asking you which one you want.
Look up Java API documentation Shift-F2 when your cursor is on a class or method name.  (You have to configure this feature with the location of the API documentation; see PS0 for more details.)
Comment/uncomment a block of code Ctrl-/ comments the highlighted region. Ctrl-\ uncomments the highlighted region.
Mark TODO items for yourself Start a comment with TODO to leave yourself a note about a piece of code that you need to fix. Eclipse will automatically put the comment in the Tasks pane, the pane where it shows your compile errors.  (If you don't see the Tasks pane, use Window » Show View » Tasks.) You can jump to TODO items or compile errors in your code quickly by double-clicking on them in the Tasks pane.
See which files you haven't committed to CVS yet Configure Eclipse so that the file icons in the Package Explorer show you which files you've added or changed but haven't committed to CVS:
  • Go to Window » Preferences... » General » Appearance » Label Decorations.
  • Ensure the CVS box is checked.
  • Still in the Preferences dialog box, go to Team » CVS » Label Decorations » Icon Decorations.
  • Check all the check boxes: outgoing, remote, added, and new resource.
Generate get() and set() methods Make sure the fields for which you would like to create get() and set() methods are declared in the class, then right-click and use Source » Generate Getter and Setter.
Run classes or unit tests that you've run recently The little "play" icon on the Eclipse toolbar runs the last class or unit test you just ran. Pull down its menu for your recent history of runs.
Turn off console autoraise When a program run under Eclipse writes to standard out (say, via println), Eclipse raises the "console" perspective. This may be annoying when you run tests, or when you use Continuous Testing. To turn this off, go to Window » Preferences » Run/Debug » Console and uncheck “Show when program writes to standard out”.
Renaming or moving packages, classes, methods, and variables   Right-click on any package, class, method or variable in the Package Explorer and select Refactor » Rename to rename it or Refactor » Move to put it in another package or class.
Emacs key bindings If you prefer to use Emacs key bindings while editing code, do:
Window » Preferences...» General » Keys » Modify and set Scheme to Emacs

Troubleshooting

Cleaning Configuration Files

If you are unable to launch Eclipse at Athena, there may be a problem with your personal Eclipse configuration files. You can fix this problem by deleting the Eclipse settings in the hidden folder ".eclipse" (and/or others, with similar names) in your home directory on Athena. If there are any files in those directories that you would like to keep, you should move them to another directory. When you're ready, you can execute the following commands to delete all of the directories and files starting with ".eclipse" and ".lasteclipse":
cd ~
rm -r .eclipse*
rm -r .lasteclipse*
Running these commands will delete any settings that Eclipse has saved from previous launches. If you are still unable to run Eclipse, you should consult an LA or another member of the 6.170 staff.

Athena Architectures

If while using Athena, Eclipse complains that the current version of the Java Runtime Environment (JRE) is unable to execute, check to see if you have switched between a Sun Athena machine and a Linux Athena machine or vice versa. (Typing uname at the prompt should show SunOS and Linux respectively.) If you have, try to use the type of machine on which you first set up Eclipse; if you need to switch at some point during the term, ask an LA for help.

Refresh to UpdateExternal Changes

When you modify a project outside of Eclipse (e.g., create a folder via the command line), you will need to explicitly refresh the package explorer in order to view the change. Please see the version control document for more information.