Eclipse Installation and Use

 

This document answers questions particularly related to the use of Eclipse in CS 102. The official Eclipse FAQ is available from eclipse.org.

  1. How do I install Eclipse on my own computer?
  2. How do I create a new project?
  3. How can I add a class to a project?
  4. How can I add an image or sound file to a project?
  1. How do I install Eclipse on my own computer?

There are several things you need to do to install Eclipse on your computer:

    1. Install the Java JDK (Java Development Kit)
      • Windows, LINUX, and Solaris users. Download and install Java 5 from http://java.sun.com/j2se/1.5.0/download.jsp. Be sure to download "JDK5.0 Update 16" (not the JRE, J2EE, or the NetBeans bundle), and select the correct version for your operating system.
      • Mac users. Your computer should have some versions of Java pre-installed. Look in the folder /System/Library/Frameworks/JavaVM.framework/Versions/ on your start-up drive to see what versions of Java are already installed. We'll be using Java 5 (ie, version 1.5) If it isn't already on your machine, you can download the latest version from http://www.apple.com/support/downloads/java2se50release3.html.

Note that while Java 6 is available, we will be sticking with Java 5 for this course. (In fact, we only use a few features from Java 5, so even using Java 1.4.2 should not be a problem.)

    1. Go to http://www.eclipse.org/downloads/index.php and download the version of "Eclipse Classic 3.5.0" that's appropriate for your operating system.
    2. Download objectdraw.jar from this link. Remember where you download this because in the next step you will need to tell Eclipse where it is.
    3. Start Eclipse.
      • Open the Eclipse menu and select Preferences.
      • Click on the icon to the left of Java to expand the Java choices.
      • Expand Build Path and then select Classpath Variables.
      • Click the New button.
      • For the name, enter OBJECTDRAW. Be sure to spell it exactly like this and in all capitals.
      • For the Path, click the File button and find the objectdraw.jar file you just downloaded.
      • Click OK and OK again.
      • Note that Eclipse may default to using Java 6. This is unlikely to be a problem, but if you want to be absolutely consistent with the lab environment you can set it to Java 5 by selecting Preferences, clicking on the icon to the left of Java, then:
        • clicking compiler and setting the compliance level to 1.5
        • clicking installed JREs and checking JVM 1.5.0
  1. How do I create a new project?
    1. Open the "File" Menu. Select "New" and then "Java Project" from the submenu.
    2. Enter the Project name.
    3. If you are not planning to use objectdraw, click Finish and skip the rest of the steps. If you are planning to use objectdraw (the usual case), click Next.
    4. Select the "Libraries" tab.
    5. Click "Add variable".
    6. Select OBJECTDRAW from the list and click "OK".
    7. Click "Finish".
  2. How can I add a class to a project?

First you should make sure the project you wish to add the class to is selected in the Package Explorer. Then there are two options. You can open the "File" menu, select "New" and then "Class" from the submenu. Alternatively you can click on the "C" icon just above the line separating the "Package Explorer" and "Editor" panes. You can also use the menu you get below the "C" to select "Interface" if that is what you want to create.

When a new dialog box appears, make sure that the name of the project is listed as the "Source folder". If not, use the browse button to find the correct project. In the "Name" field, type the name of the new class. While you can add information in the "Superclass" and "Interfaces" fields, it is often simpler just to add it yourself after the class has been created. Click on "Finish" to finish creating the new class as part of your project.

  1. How can I add an image or sound file to a project?

The following technique can be used to import any type of file into an Eclipse project, not just image and sound files. The files will be copied into the project.

    1. Select the project to import the file(s) into in the Project Explorer panel.
    2. Open the File menu. Select Import. Select "File system" (if you don't see it, it's under "General"). Click Next.
    3. Click the Browse button. Find the folder containing the files to import. Select Choose.
    4. Click on the folder name (not the check box) in the left column.
    5. Select the files to import in the right column (by clicking in the check boxes).
    6. Click Finish.

Note that in some cases you may be able to simply drag a sound or image file into the Project Explorer panel.