Eclipse Setup

Install Java & Eclipse

Follow either section depending on your operating system.

Instructions for Mac

We’ll be installing Java and Eclipse. Mac users can use a helpful tool called Homebrew to install all of these in only a couple steps (you can install anything, really!).

First, install Homebrew if you have not yet:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then, install Java and Eclipse in this one command:

brew install --cask eclipse-java adoptopenjdk/openjdk/adoptopenjdk8

Instructions for Windows

  1. Install Java. First, to run Eclipse, a Java Runtime Environment (JRE) must be installed. You verify that you have the JDK 8 installed by running the java -version command (from the Command prompt in Windows or the terminal on Mac):

    $ java -version
    java version "1.8.0_172"
    Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
    

    You should see output similar to lines 2-4 above. Any higher version of Java will also work for this class.

    If you do not have the JDK 8 or newer installed, you can download and install Java 8 from this site (after accepting the terms & conditions). Make sure to install the JDK version called “Java SE 8”.

Note: Make sure you do this step before installing Eclipse.
  1. Install Eclipse. We recommend using the latest version of Eclipse (Eclipse IDE 2020‑12), but earlier versions should work too. Make sure you have completed Step 1 before installing Eclipse.

    1. Visit the Eclipse installer page.
    2. Click on the link for your platform on the right side of the screen (under “Download”) and unzip the downloaded file to get a file called “Eclipse Installer”.
      • Note: The 64-bit Windows version of Eclipse may not be able to locate Java installations. If this happens, use the 32-bit Windows version instead.
    3. Run the Eclipse Installer. Select “Eclipse IDE for Java Developers” and then “Install” to install Eclipse.
    4. Launch Eclipse.
    5. The first time you run Eclipse, you need to choose a workspace (a folder that stores your projects).

Setting up a Java Workspace

For the Java portion of the course, we recommend creating a new workspace. You will only need to do this once this semester. To create a workspace:

  • Click File –> Switch Workspace –> Other …
  • Click Browse… and navigate to the place where you want to store your Java workspace on disk.
  • Create a new folder for your Java workspace and select it. Give it a meaningful name like “CIS1200Workspace” so that you can find it easily.

To switch between workspaces, select File –> Switch Workspace.


Setting up a homework in Eclipse

  1. To setup one of the homeworks in Eclipse, first download the zip archive off of the homework’s writeup page (for example, hw06.zip). Unzip that downloaded archive.
  2. Open Eclipse, and open the Java Workspace created above.
  3. Import the homework:
    1. Press File –> Import
    2. Then scroll down to Maven then click Existing Maven Projects
    3. In the popup, press Browse, and navigate to the unzipped archive downloaded in step 1 (i.e: hw06.zip). Choose that folder.
    4. If all goes well, it should automatically detect pom.xml. Press finish.

After importing, your Package Explorer should look something like the following (for homework 6, at least):

For a video demonstration of the above steps, refer to this gif:


Running the Project

To run your project code, we created special “run configurations” to run them. You can access these by pressing the small dropdown arrow next to the green play button. You may be able to see the different options right away, or you may need to click the “Run Configurations…" option if this is your first time setting up the configurations. Then, under “Maven Build” you should see the “Run Project” option. Open that, then press “Run”. You can see the process in the below gif

Tip: If you get a “Base directory name can’t be evaluated” error, try clicking on and opening one of the files in your project and try again.

Running JUnit Tests

Unit testing is a method of testing source code that verifies that individual units are working properly. A unit of code refers to the smallest testable part of an application. In OCaml, this was a function, and in Java, this is a method. JUnit is a Java package that implements unit testing. Eclipse provides tools to automate the creation of JUnit tests. It also provides a good interface for running the tests. Together these two tools make systematically testing your program very easy.

To run JUnit tests, right-click on the JUnit testing file that you want to run, then go down to “Run As”, then “JUnit Test”. Watch the below gif as well!


Running the Style Checker

Like OCaml, we have a Style Checker for Java that we will use to grade your code syntax and style. Luckily, you can use the same Style Checker that we have in Gradescope locally. Similarly to Running your Project, this is done using a “Run Configuration” which we have provided to you in the project. See the instructions above for information on where to find and how to run these custom configurations, and watch the gif below:


Formatting your Code

To assist passing the Style Checker’s strict style guidelines, we have also provided a formatter in Eclipse. Similarly to Running your Project, this is done using a “Run Configuration” which we have provided to you in the project. See the instructions above for information on where to find and how to run these custom configurations, and watch the gif below:


Using the Eclipse debugger

For debugging Java code, the Eclipse debugger can turn out to be more helpful than just using print statements, especially when you start having really complex code. We suggest watching CIS 1210’s YouTube tutorial on how to use the Eclipse debugger.