Using Eclipse and Ant

Overview

Eclipse is an open source project donated by IBM. Eclipse has some important features such as an integrated build environment, remote debugging etc.

Ant is a java based build-tool. Ant replaces other tools such as make and nmake. Ant uses a XML-based build script and is itself an open source project. Since Ant is written in Java, the same build scripts can run on any platform.

Set Up of ANT and ECLIPSE

  1. Check-out your project code if you have not done so already.
  2. Install Eclipse.
  3. Install Ant.
  4. Add Ant's jar files (ant.jar and optional.jar) to your classpath.

Building the project in Eclipse

If you type "ant" at DOS prompt, it automatically uses build.xml as your build file. Eclipse has built-in support for Ant. Follow the steps below to create a project in Eclipse:

  1. Select File->New->Project
  2. Select Java in left pane and 'Java Project' in the right pane.
  3. Click Next.
  4. Enter a Project name (eg: Athena)
  5. Unselect 'Use default' and browse to your working directory (where your source code is).
  6. Click 'Yes' on the dialog that says location already exists. Make sure you have Athena/java in the 'Use source folders contained in the project'.
  7. Remove any other options created in the list box under 'Use source folders contained in the project'.
  8. In 'Build output folder' enter Athena/build/classes.
  9. Click Finish.
  10. Select Run->ExternalTools->Configure.
  11. Enter ANT as name and browse for ant.bat for the Tool Location in the directory where you installed Ant.
  12. For Working Directory, select 'Browse Options', select 'Browse workspace' and select Athena Project.
  13. select OK.

You can override the properties set in bulid.xml simply by setting your own properties in build.properties file. So instead of modifying build.xml which could change from time to time, you can maintain a private copy of your build.properties. This way you get all the latest updates from build.xml, and you can override any of those properties by setting them in your own build.properties.

To build the project from Eclipse, right click on build.xml file and select 'Run Ant...'. Then choose the target you want: "dist" is the default task which builds and prepares the distribution staging area.

Modify the build.properties file and add set the property install.dir=<Your mid-tier install directory> (use double backslash for a backslash in the path) and save the file.

For debugging a servlet, you need have the servlet JVM running in debug mode.

In Servlet Exec, go to Virtual Machine->Options and add the following options:

-Xrunjdwp:transport=dt_socket,server=y,addrress=8000,suspend=n
-Xdebug

To compile and install, stop the web server. Select 'Run Ant...' again, unselect "dist" and select "install" to install the build to your install location. Start web server.

Debugging the Application

Eclipse allows you to debug the JVM running in the web server using Java Debug Wire Protocol. With this you can debug web servers on a remote machine as well as your local machine. The JVM options set above enable the JVM to debug remotely.

To debug, select Run->Debug...

Right click on 'Remote Java Application' and select New, enter a Name. Select your project. Select Connection Type: Standarad(Socket Attach) In Connection Properties, enter Host: localhost and Port 8000 (or 8080). Click Apply and then click on Debug. Open any source file and put a break point by right click on the left gray bar of the source window