Java web applications
From Humanitarian FOSS Summer Institute 2009
Contents |
Java Web Applications
Handouts and resources
- Lecture notes: Media:lecture-slides.pdf
- Petstore Eclipse project: Media:petstore-project.zip
- Apache Tomcat
- Sysdeo Eclipse Tomcat plugin
Configuration
We need to configure Eclipse to know about Tomcat, and we also need to import a sample project into Eclipse to see an example of a web application.
Tomcat
Download and install Apache Tomcat 6.x from the link above.
If you are working on a server on which Tomcat has already been installed and you are sharing the installation with other developers, then you need to set up a "local" Tomcat base directory; the reason is that Tomcat needs write access to a number of directories to run, and since it will be running under your username, you need to create these directories.
- Create the following directory structure:
catalina/ conf/ logs/ temp/ webapps/ work/
(the name of the top-level directory does not have to be catalina).
- Copy the following files from <tomcat_home>/conf to the conf subdirectory: server.xml, tomcat-users.xml, web.xml.
- Edit tomcat-users.xml to have the following lines:
<tomcat-users> <role rolename="manager"/> <user username="tcmanager" password="abcd1234" roles="manager"/> </tomcat-users>
(you can choose any username and password you like).
Configure Eclipse to use Tomcat with your local base directory
- Open "Preferences" and click on "Tomcat."
- If you don't have a Tomcat preference, download and install the Sysdeo Tomcat plugin for Eclipse from the link above.
- Select Version 6.x
- Choose the Tomcat installation directory for Tomcat home.
- Select "Server.xml" for the Context declaration mode.
- Untie the Tomcat twistie and select Advanced.
- Choose your local Tomcat base for Tomcat base.
- Select JVM.
- For JRE, choose at least 1.5.0; if there is an operating-system default indicated, use it.
- You may configure the Tomcat manager if you like, although for this exercise we will not need to do so.
Install the Petstore project
To install the Petstore project, follow these instructions:
- Download the Petstore project ZIP file above.
- In Eclipse, select File->Import...
- Untie the General twistie and select Exiting Projects into Workspace.
- Select Select archive file and choose the ZIP file you just downloaded.
- Ensure that the petstore project is selected and click Finish.
- Choose the Java perspective.
- Right-click on the project name and select Build Path->Add External Archives...
- Navigate to the Tomcat installation directory; go to the lib subdirectory and select servlet-api.jar
- Create a petstore database in MySQL, and populate it by sourcing the petstore.sql file in the db subdirectory of the petstore project. Change the value of the db_name field in Login.java to the name of your database.
- Change the build.properties file to have the correct appserver.home path. For example, appserver.home=/home/gen_coms03/tomcat

