CSE 373, Winter 2018: Eclipse overview

High-level overview

The welcome page

When you open Eclipse for the first time, you may see a "welcome" page. Start by closing that page: click the small "x" icon in the "Welcome page" tab (circled in red below).

Views

Once you've loaded your project (and opened a file), you should see something that looks roughly like this:

This screen can seem very noisy, but very roughly, you can categorize every element in this window into four different groups: the menubar, the toolbar, the editor, and views.

The first three things should be self-explanatory. The menubar contains a bunch of commands and options, the toolbar (directly below) contains buttons for running, testing, and inspecting code, and the editor is where you edit code.

A view is basically a "tab" that contains some piece of information about your code. For example, in the picture above, there are four different views visible: Package Explorer, Gradle Tasks, Task List, and Outline.

Eclipse lets you open many different kinds of views on your code, and lets you rearrange them at will. You can drag-and-drop a view from one part of a window to another or can close views you don't care about. If you accidentally closed a view, you can reopen it by selecting "Window" > "Show View" from the menubar.

Here's what Eclipse looks like after I closed some of the views I personally don't care about, and moved the "Outline" view from the right to the bottom:

Perspectives

A perspective is a particular arrangement of views.

The basic idea is that depending on what we're doing, we may find some views useful and may sometimes find other views completely irrelevant. To support this, Eclipse lets us save a particular collection of views as a "perspective". We can then switch between different perspectives with ease.

For example, the picture up above is the "Java editing" perspective: it shows us views that are useful when we're editing code. Now, suppose we want to run the debugger (we will release a "Eclipse debugging guide" later that covers how to do to this in more detail. When we do, Eclipse will shift and look like the following:

Notice Eclipse has opened up a bunch of views related to debugging code. Once we're done debugging, we probably want to return back to the "Java editing" perspective. There are two ways to do this:

  1. The first way is to click "Window" > "Perspective" > "Open Perspective" > "Java" from the menubar.
  2. As a shortcut, you can instead click the icon with a "J" at the very far right of the toolbar (upper-right corner). Eclipse will display icons representing each perspective you've used so far to help make it easier for you to switch between them.

Running code

To run code, open the Java file you want to run and click the green circle with the white arrow in the upper middle-left of the screen.

If Eclipse asks you to "select a way to run X.java", select either the "Java Application" or "JUnit Test" options. Never select the "Gradle Task" option.

You can do the same thing to run unit tests. Once you do run a unit test, you can see the results in the left and lower half of the screen. Click on each test to get more details. For example:

Running style checks

Once your stylechecker is installed, you can run it by right-clicking on your project in the project view pane to the left and clicking "Checkstyle" > "Check Code With Checkstyle".

This will make Eclipse add warnings throughout your files whenever it finds a style violation. However, having to check every file is inconvenient: to see the full list of all style errors, click "Window" (in the menu bar) > "Show View" > "Other...".

In the window that appears, open the "Checkstyle" folder, select the "Checkstyle violations" option, and click ok. (You should have to do this only once: once you've opened the view, it'll stay open).

Now, when you run checkstyle, Eclipse should look something like this:

If the warnings are bothering you and you want to clear them for now, right-click the project again, and select "Checkstyle" > "Clear Checkstyle violations".

To re-run the checks, right-click the project and select "Checkstyle" > "Check Code With Checkstyle".