Eclipse Tricks (for Java)

Thomas J. Kennedy

Contents:

Vim (and to a lesser degree) Sublime Text are my editors of choice. Many students prefer an IDE that is configured out of the box. In general I recommend Eclipse. You might remember Eclipse from CS 252.

There are a few reasons I usually default to recommending Eclipse:

  1. It is introduced in CS 252.
  2. It is used in CS 350.
  3. It has plugins for C++.
  4. It has has plugins for Git.
    • Git is good tool to explore in your free time (instead of watching TV).

1 Using Gradle with Eclipse

In my Gradle build scripts (i.e., build.gradle) you will find lines in the form:

apply plugin: "java"
apply plugin: "application"
apply plugin: "eclipse"

or


plugins { id "java" id "application" id "eclipse"

These lines are followed by settings for:

  1. Compiling and running a program with ./gradlew run
  2. Compiling and running unit tests with ./gradlew test
  3. Generating an Eclipse project with ./gradlew eclipse

It is the last Gradle task (i.e., eclipse) that interests us. This allows us to skip the manual setup of a Java project.

2 Eclipse Import Instructions

To get started grab one of my Java examples or Java assignments.

  1. Place a copy of a zip file in a memorable location (i.e., one you will remember).

  2. Extract the zip file.

  3. If your are on Linux or macOS:

    1. Open a terminal in the selected directory.
    2. Run ./gradlew eclipse
  4. If your are on Windows:

    1. Open a Command Prompt window or Powershell Window in the selected directory.
    2. Run .\gradlew.bat eclipse
  5. Open Eclipse.

  6. Go to File -> Import Existing Project.

  7. Select the directory you chose in Step 1.

3 Eclipse Video

I have created a few Eclipse lectures for other courses. One video, Setting Up A Java Project, covers the basics of setting up a Java project.

Jump to time 20:28 if you are using the ./gradlew eclipse import method.