Using Eclipse

Using Eclipse


Introduction

Throughout the semster, you have the option of using Eclipse as your IDE. While learning Eclipse can be frustrating, it has some very nice features that make up for it in the end. This tutorial will go over creating a new project, using JUnit 3.8.1, setting up the Test-Tracker project, using Subclipse, and generating Javadocs with Eclipse.


Creating a Project

The following will walk you though creating a project from scratch:

  1. Select File->New->Project
  2. Select "Java Project"
  3. Enter the name of your project
  4. Make sure that the JDK compliance is at 5.0
  5. You can specify to have the class files in a sepearte folder in the "Project Layout" section
  6. Click Finished

Creating a Project from an Existing Source Tree

To use the test-tracker source folder, follow these steps

  1. Put the source tree in the project workspace
  2. Select File->New->Project
  3. Select "Java Project"
  4. Enter the name of your project: test-tracker
  5. Click Finished
  6. To make sure that the project is using JDK 5.0:
    1. Select Project->Properties
    2. Select Java Compiler
    3. Check "Enable Project Specific Settings"
    4. Set "Compiler Compliance Level" to 5.0

Adding a JAR File to Your Project Build Classpath

Sometimes you need to include an external JAR file as a library. Test-Tracker is already set up to use the JavaMail API because we have included the JAR files already. If you want to do this with other projects you are working on, follow these steps:

  1. Go to the project properties
  2. On the left column: click on "Java Build Path"
  3. Click on the "Libraries" tab
  4. Click on "Add JARs..."
  5. Select the Jar

Running Ant build.xml tasks

Running Ant tasks from the command line may not always be what you want. If you want to run them in Eclipse, you will need to follow these steps:

  1. Go to Run -> External Tools -> External Tools
  2. Right Click on Ant Build and select New
  3. Select the targets you wish to run in the Targets Tab
  4. If the build file needs to be specified or changed, do so in the Main tab
  5. If you need to add classpath jar files, do so in the Classpath tab
  6. You may need to add the tools.jar from ...\jdk1.5.0_0#\lib\tools.jar
  7. You may need to add the JUnit3.8.1.jar file to the classpath to run test or coverage
  8. Select build.xml -> Run As -> External Tools -> [the name of your ant task command]

Adding jar files to the Ant general classpath can be done by selecting: Window > Preferences > Ant > Runtime


Setting Up JUnit

JUnit should already be set up for test-tracker. We are currently using JUnit 3.8.1 as a class. To use JUnit on other projects, follow these steps in Eclipse:

  1. Right click on your test-src folder
  2. Select new->JUnit Test Case
  3. If a popup asks you if you want to add junit.jar to the build path, select yes
  4. Remember, Each test case you add should end with "Test". (i.e. SomethingTest.java)

Generating Javadoc Files

For this class, we already have the Ant target (ant doc) set up so that you should not have to do anything extra to generate your documentation. If, in other projects, you wish to use Javadoc with Eclipse, follow these steps:

  1. Select Projects -> Generate Javadoc...
  2. Click on configure
    • The javadoc.exe is located in the Java\bin folder on your computer
    • For example: C:\Program Files\Java\jdk1.5.0_02\bin\javadoc.exe is where I found mine.
    • The linux labs use: /usr/java/jdk1.5.0_08/bin/javadoc
  3. Select the source folder of the project you wish to document
  4. Enter the destination for the documentation files
  5. Click on next twice.
  6. In the large text area (extra javadoc options), enter the extra tag information:
    • -tag invariant:t:"Class Invariants:"
    • -tag pre:cm:"Pre-Conditions:"
    • -tag post:cm:"Post-Conditions:"
  7. Click finish.

Setting Up Subclipse (Subversion on Eclipse)

Follow the steps here: subclipse.tigris.org/install.html for directions on how to install the Subversion plugin for Eclipse

After setting up Subclipse, follow these steps:

  1. Select "Window -> Open Perspective -> Other"
  2. Select "SVN Repository Exploring"
  3. Select "Window -> Preferences"
  4. Select "Team -> SVN"
  5. Change the "SVN Interface" radio-button to "JavaSVN (Pure Java)"

While in the SVN Repository perspective, you can add a repository. The URL you use will follow this schema:

  • svn+ssh://cs.byu.edu/users/groups//test-tracker

Using Subversion

If you want to use Eclipse in syncronizing your Subversion repository:

  1. Create your repository and check it out into your workspace.
  2. Open eclipse and follow the steps to create a project from the existing source tree
  3. On the Package Explorer, notice the icon for your project has a maroon astrix on your project folder
    • This icon shows that the folder has out of date content
  4. Adding a new package will show a question mark on the new package icon.
    • This icon shows that the folder is unrevisioned content
  5. Lets add a few classes and look at the different options that we can perform with right-click
  6. Notice when we "Add to Version Control", a blue plus icon is shown on each item added.
  7. When we want to commit, a dialogue will ask to verify each operation.
    • Only checkmark items you want under version control. Eclipse will make some files you may not want in your repository.
    • Having extra files under version control can create a large overhead and wasted space in your account. You may have Eclipse/Subversion ignore items by selecting "Team->Add to svn:ignore"
    • You must input a log message to explain the changes. This log can be viewed by selecting "Team->View in Resorce History".
  8. When we commit, the items will now have yellow tube icons for each item that is up to date
    • Each item has a name, revision number, revision date, and revision author.
  9. When you edit a file, it will have the maroon astrix afixed to it to show that it is now out of date. If you wish to revert the file to the state it was when you last updated, you may select "Team->Revert".

  10. There are many other Subversion commands that can be used from Eclipse. Use your sandbox repository and experiment with your team mates to learn more.

0 comments: