Using Eclipse

Using Eclipse for Application Development

Configuring Eclipse

The first step is to configure Eclipse to use the Tomcat plugin. Do the following:

  1. In the main menu, choose Window -> Preferences .
  2. In the opened window, expand the list item Tomcat (in the left frame).
  3. Click on Tomcat.
  4. In the right frame do the following: eclipse screenshot
  5. In the left frame, click on Advanced in the list expanded under Tomcat.
  6. In the right frame, write your chosen $CATALINA_BASE directory in the Tomcat base text field.
  7. eclipse screenshot
  8. In the left frame, click on Tomcat Manager App in the list expanded under Tomcat.
  9. In the right frame, do the following: eclipse screenshot

Now Eclipse is set to work with Tomcat, you can open a Tomcat project.

Opening a Tomcat Project

First create your Web Application Directory under $CATALINA_BASE/webapps/. For detailed instructions see the section about direct programming.

To edit your application, open a Tomcat project as follows:

  1. Choose the File menu item in the main menu. In this menu item choose New -> Project....
  2. In the opened form, choose Java (on the left frame) and Tomcat Project (on the right frame).
  3. Press the Next button.

  4. Choose a name for your project and unmark the Use default check box. As a working directory (the Directory text box) choose the Web application you created (under $CATALINA_BASE/webapps/).
  5. Click Next.

  6. In the new window, clear all the data: unmark the check box Can update server.xml file and clear the text fields (Context name and Subdirectory to set...).
  7. Click Finish.

  8. If a message box is opened and asks you whether you would like a Java perspective to be opened, choose Yes.

Editing Your Application

To add Java classes to your project, right click on your project element on the left frame, choose New -> Class... and follow the regular class-creation instructions. Make sure that the location of the source file is WEB-INF/src/.

If you use packages (for example, to use classes from JSP files), you will have to define them first. To create a package, right click on your project element on the left frame, choose New -> Package... and fill the package name. When you add classes under this package, Eclipse will automatically put the compiled class in the suitable location under WEB-INF/classes/ (e.g. WEB-INF/classes/package-name/class-name.class).

Note that Eclipse does not update the file WEB-INF/web.xml, therefore it is still up to you to update this file.

You can use the buttons with the cat figures to start/stop/reload Tomcat, or alternatively use the shell for this purpose.

To create files that are not Java classes (HTML, JSP, XML, XSL, etc...), right click on your project element on the left frame, choose New -> File and fill the file name. You may also add sub directories (New -> Folder) and add files under them. This time, you will have right click on the folder element.

Screenshot images were donated by Shlomi Levi (shloml01@cs). Thank you Shlomi.