Eclipse & Tomcat Example Webapp
(Free Web Tutorial)
by Michael Thomas
Tomcat Home Page
Setup Eclipse projects for the Tomcat Example webapps that get
installed with Tomcat so you can edit & compile changes to existing examples.
On the Eclipse Home page, you can download
the whole Eclipse site (all content, tutorials & examples) !!!
This tutorial covers: Eclipse 3.1.1 (as of 05/14/08), Apache Tomcat
6.0.16 (as of 05/25/08)
Prerequisites
- Have Eclipse installed.
- Have Tomcat installed (with Struts if you want to complete that section).
- Know how to Start/Stop Tomcat and/or Reload a WebApp (we have a
Tomcat Tutorial on that).
- This tutorials has been tested in the following environment:
Date: 05/14/08
OS: Win XPro
JDK: jdk1.6.0_03
Objectives
- Create a new Eclipse project tied to existing webapps running on Tomcat
that were installed with Tomcat.
- With a copy of the Tomcat examples webapp you can now make changes and
experiment.
General Info
- Reload Web App or Stop/Start Tomcat Service
- FYI - Remember if you make changes to the web.xml or
.java source files you will need to "Reload" the Webapp or Start/Stop the "Apache Tomcat" service.
(Note: There is a free Tomcat Tutorial which covers those steps.)
- To Stop/Start the Tomcat service:
Control Panel, Administrative Tools, Services, then right click on "Apache
Tomcat" and choose Stop, then Start.
- To reload the webapp:
http://localhost:8080
, click "Tomcat Manager", find the webapp and choose "Reload"
examples - Tomcat's example webapp.
- Verify you have Tomcat's example webapp.
- Using Win Explorer find the Tomcat Webapp directory.
Possible directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- examples - this webapp exits (the directory) then you can
continue this tutorial.
- http://localhost:8080/examples
- make sure Tomcat is running then verify this works!
- Create the Webapp
- Stop Tomcat
- Let's copy the existing web app so you can make changes without changing
the original web app.
- Go to the Tomcat webapps directory:
Ex: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
- Make a copy of the directory "examples" and name it:
myeclipse-tomcat-examples
- Verify the new webapp works
- Eclipse - Create a Java Project -
- Launch Eclipse
- File, New, Project, Java Project, Next
- Project Name:
myeclipse-tomcat-examples
- Contents: "Create project from existing source".
- Click "Next"
- Click "Browse" and locate the directory in the Tomcat WebApp
directory.
Click to select.
Ex Directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\myeclipse-tomcat-examples
- Folder: myeclipse-tomcat-examples
- Click "OK"
- Click "Next"
- Check the box - Allow output folders
for source folders.
Note: This webapp has the .java & .class files in the same
direcory.
- On the "Java Settings" screen change the "Default output folder":
myeclipse-tomcat-examples/WEB-INF/classes
(Note: This webapp has a "plugin" directory that has .java
files that do not match the scheme of the rest of the .java & .class
files. Ex directories: WEB-INF\jsp\applet & jsp\plugin\applet\examples)
- Click "Finish"
- WARNING READ THIS: If you see the prompt "The output folder has changed ...." click
"No".
If you click yes you will delete a needed directory.
- Eclipse - Build Path - add the Struts/Tomcat lib jars files.
- Right click on the project.
- Click "Build Path", "Configure Build Path", then
click the tab "Libraries"
- Check to make sure that the "JRE System
Library" is listed.
If not, click "Add Library", "JRE System
Library", "Next", "Finish".
Notes:
Under the tab "Order and Export" this lib file should be directly under
the WEB-INF/src directory.
You can't compile .java files without this library!!!
- Click "Add External JARs"
- Browse to the Tomcat common library directory.
Ex: C:\Program Files\Apache Software Foundation\Tomcat
5.5\common\lib
- Select all of the JAR files and click "Open".
- Click "OK" to leave the "Java Build Path" screen.
- You're finished.