CIT 591 Getting Started With Eclipse
Fall 2004, David Matuszek

Downloading and installing

The main page is http://www.eclipse.org/ ; start there for everything.

Click on "downloads" in either the main panel or the navigation panel; this will bring you to a page where you can select either the Main Eclipse download site or one of several mirrors. I suggest that you get the "Latest Release." I'm using Release 3.0.1, which is the latest release at the time I'm writing this.

Installation is simple, but you must already have the Java SDK installed. Unzip the file and double-click eclipse.exe.

Getting started

The following is slightly modified from http://www.eclipse.org/eclipse/faq/eclipse-faq.html#users_4:

How do I write a simple "Hello World" program?

To write a "Hello World" program follow these steps:

  1. Start Eclipse.
  2. Create a new Java Project:
    1. File->New->Project.
    2. Select "Java" in the category list.
    3. Select "Java Project" in the project list. Click "Next".
    4. Enter a project name into the Project name field, for example, "Hello World Project".
    5. Click "Finish"--It will ask you if you want the Java perspective to open. (You do.)
  3. Create a new Java class:
    1. Click the "Create a Java Class" button in the toolbar. (This is the icon below "Run" and "Window" with a tooltip that says "New Java Class.")
    2. Enter "HelloWorld" into the Name field.
    3. Click the checkbox indicating that you would like Eclipse to create a "public static void main(String[] args)" method.
    4. Click "Finish".
  4. A Java editor for HelloWorld.java will open. In the main method enter the following line.
         System.out.println("Hello World");
  5. Save using ctrl-s. This automatically compiles HelloWorld.java.
  6. Click the "Run" button in the toolbar (looks like a little man running).
  7. You will be prompted to create a Launch configuration. Select "Java Application" and click "New".
  8. Click "Run" to run the Hello World program. The console will open and display "Hello World".

Using the tutorials

The tutorials are online, and I haven't found an easy way to download them so that they can be used offline.

To start a tutorial, first start up Eclipse. Go to the Help menu and choose Help Contents. This should open a browser window with contents in the leftmost pane and "Using Eclipse help system" in the right pane. (I have found that if you try to open a second window this way, it comes up with nothing in the leftmost pane; so use just the one window.)

In the leftmost window, click on Workbench User Guide. Don't click on the icon next to it--that doesn't do anything--but click on the words themselves.

At this point, Getting started looks an acts like a link, but it doesn't do any good to click on it. Instead, click on the + to its left. This opens up and you can click on Basic tutorial, which is a link that opens a page that says "Basic tutorial" and little else. As before, if a link has a + to its left, you need to click on the + to open things up. Doing this again gets you to The Workbench, which is the first page with any useful information on it.

As you step through the sections of a tutorial, you will have to keep track of where you are; the Contents menu on the left does not highlight the current section.

Both Eclipse and the tutorial require a lot of screen space, so you will find yourself frequently switching back and forth between the two. It may help to resize the windows so they are full screen width but not as tall, so you can put one above the other.

You should work through at least these tutorials:
      Workbench User Guide -> Getting started -> Basic tutorial
      Java Development User Guide -> Getting started -> Basic tutorial

Running JUnit tests

Before you can write JUnit tests you have to add the junit.jar library to your build class path.

  1. Create a project.
  2. Right-click on your project and choose Properties.
  3. Click on Java Build Path.
  4. Click on the Libraries tab.
  5. Click on Add External JARs....
  6. Navigate to junit.jar. It should be in a location such as ...Eclipse 3.0.1\plugins\org.junit_3.8.1\junit.jar.
  7. Select junit.jar, click on Open, click on OK.

To create a test class:

  1. Open the New wizard (File > New > Other...)
  2. Select Java > JUnit in the left pane and TestCase in the right pane and click Next.
  3. Enter the name of your test class and click OK.

To run your test class, select your test class and choose Run as > JUnit Test from the Run drop-down menu in the toolbar.

Pay special attention to this Eclipse tutorial: Help -> Help Contents -> Java Development User Guide -> Getting Started -> Basic tutorial -> Writing and running JUnit tests

Also read: JUnit Test Infected, http://junit.sourceforge.net/doc/testinfected/testing.htm.