CS 133: Working in Eclipse

Eclipse is a graphical software development environment that you might be more comfortable with working in. The instructions we provide were tested most recently with Eclipse Photon with Java 1.8

Setting the Lab Up in Eclipse

Running Ant Build Targets

If you want to run commands such as ant test or ant systemtest, there are a couple options from within Eclipse:

  1. Add an Ant window in Eclipse: Go to Window -> Show view -> Ant. When the view opens (likely on the right), click the "add buildfile" icon. In the pop-up dialog box, select the build.xml under "cs133-lab1". Once the window appears in your workspace, you can run an ant target by right-clicking it, selecting "Run As," and then "Ant Build...". In the dialog box that pops up, you should see the target you right-clicked with a checkbox next to it in the "Targets" tab. Arguments such as "-Dtest=testname" can be specified in the "Main" tab, "Arguments" textbox. Clicking the "Run" button should run the build targets and show you the results in Eclipse's console window.

  2. Using build.xml in the Package Explorer: You can bring up that same dialog box by right-clicking build.xml in the Package Explorer (on the left) and selecting "Run As," and then "Ant Build...". You'll have to check off your desired targets in the "Targets" tab.

Running Individual Unit and System Tests in the JUnit Tab

You can also run the unit or system tests by using the Package Explorer to run JUnit tests. However, note that running tests this way won't necessary check for your code's adherence to Java 1.8, so be sure to periodically compile using Ant. To use the JUnit tab, go to the Package Explorer tab on the left side of your screen. Under the "cs133-lab1" project, open the "test" directory. Unit tests are found in the "simpledb" package, and system tests are found in the "simpledb.systemtests" package. To run one of these tests, select the test (they are all called *Test.java - don't select TestUtil.java or SystemTestUtil.java), right click on it, select "Run As," and select "JUnit Test." This will bring up a JUnit tab, which will tell you the status of the individual tests within the JUnit test suite, and will show you exceptions and other errors that will help you debug problems.

Running a Jar file Using Eclipse

You can run a jar file from within Eclipse. For example, to run the jar command using dist/simpledb.jar described at the end of Section 1.2, take the following steps (note: ant dist creates the jar file, follow the directions above for running ant targets within Eclipse):

  1. Right-click on simpledb.jar in the Package Explorer (under dist) then click "Run As" and then "Run Configurations...".
  2. On the left side of the dialog box, select "Java Application", then click the icon for "New Launch Configuration" (a picture of a document with a plus sign, near the top on the left).
  3. You can pick a name for the configuation at the top of the right part of the dialog box, e.g., "SimpleDb"
  4. Set the project, which will likely be cs133-lab1
  5. Set the main class to SimpleDb

Your configuration is set up! You can use the "Arguments" tab to run the jar with command-line arguments. For example, if you want to run the convert command from Section 1.2, you would enter the following in the program arguments box: convert file.txt N, substituting the correct file location and value for N. Then click the "Run" button at the bottom of the dialog box. The next time you want to use this particular run configuration, you should see its name listed under "Java Application".