Tomcat - First Steps
(Free Web Tutorial)
by Michael Thomas
Tomcat Home Page
In this tutorial you will install Tomcat, test the install, install your first web app and
view the Tomcat documentation.
Note: On the "Tomcat Home Page", you can download
the whole site (all content, tutorials & examples) !!!
This tutorial covers: Apache Tomcat
6.0.16 (as of 05/25/08)
Prerequisites
- Tomcat 6.0 requires JRE 5.0.
(For help on obtaining Java's JRE/JDK we have a "Java First Steps" tutorial
on the home page of "Free Web Tutorials on Java & Web Technologies" )
- This tutorials has been tested in the following environment:
Date: 05/25/08
OS: Win XPro
JDK: jdk1.6.0_03
Objectives
- Install Tomcat
- Test your install
- Install your first web app
- View Tomcat's docs.
Version Notes:
- Tomcat 3.x - implements the Servlet 2.2 and JSP 1.1 specifications.
- Tomcat 4.x - implements the Servlet 2.3 and JSP 1.2 specifications.
- Tomcat 5.x - implements the Servlet 2.4 and JSP 2.0 specifications.
- Tomcat 6.x - implements the Servlet 2.5 and JSP 2.1 specifications.
Installation Notes for Win XP - (Install File: jakarta-tomcat-5.5.7.exe)
- apache-tomcat-6.0.16.exe - download this file from the Tomcat home page:
http://tomcat.apache.org/
- On the left side of the screen under "Download" click "Tomcat
6.x"
- Sometimes the beta versions are listed first. Find the first
version that doesn't have "-beta" at the end.
- Find the section "Binary Distribution" section
- Download notes:
I suggest saving them to your local
and then later installing (RUN).
To download the file, right click on the link and
choose "Save as Target" to save to your local (do not click "Run" after
the download. Click "Close").
- Download the following files.
- Find the sub-section "Core" links.
- "Windows Service Installer" (~5.15 meg) -
this version is designed to be started as a windows service.
(ex file: apache-tomcat-6.0.16.exe)
- Upgrade WARNING: If an older version of Tomcat is installed then uninstall
the current
Tomcat version first.
- Uninstall Tomcat so you can update the version.
- I suggest that you Stop the Tomcat service first.
(Ex: Start, Settings, Control Panel, Administrative Tools, Services.
Right click on "Apache Tomcat" then click "Stop".)
- Make a backup copy of the current Tomcat x.x
directory.
(IE: C:\Program Files\Apache Software Foundation\Tomcat 5.5 )
- Uninstall Tomcat – Programs, "Apache Tomcat
x.x.x", "Uninstall Apache Tomcat x.x.x"
(Other option: Control Panel, Add or Remove Programs, then
find "Apache Tomcat x.x.x").
- Next you will be prompted with:
Remove all files in your Tomcat 5.5 directory? (If you have anything
you created that you want to keep, click No)
- Click "No" - so that you keep all of your work files.
Warning: "Yes" will delete all of them!
- You should see "Completed". Click "Close".
- Install Tomcat Core
- Run the .exe file you downloaded. (Note: You can run it from
any location.)
- On the Welcome screen click "Next"
- On the License Agreement screen click "I Agree"
- Choose Components Screen - I would check
"Start Menu Items", "Documentation"
& "Webapps".
Click Next.
- Choose Install Location Screen
Default is: C:\Program
Files\Apache Software Foundation\Tomcat 6.0 (~10 meg required)
Click Next.
- Configuration Screen:
Http/1.1 Connector Port: 8080
Administrator Login options:
- User Name: admin
Password: <blank is the default> (I suggest you put a password).
- To change later: (UNDER CONSTRUCTION)
Click Next.
- Java Virtual Machine - install should find the directory.
- My Ex: C:\Program Files\Java\jre1.6.0_03
- To change later: (UNDER CONSTRUCTION)
- Click "Install"
- "Completing the Apache Tomcat Setup Wizard" - leave the defaults checked
- Checked - Run Apache Tomcat
- Checked - Show Readme
- Click "Finish"
- Notes:
- Release notes are located at:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\docs\RELEASE-NOTES.txt
- Windows Services - Q&A
I suggest that you get familiar with Starting and
Stopping the "Apache Tomcat" service.
- Services Panel
Q: How do I get to the "Services" panel?
A: Control Panel, Administrative Tools, Services
- Startup Type
Q: How do I make "Apache Tomcat" automatically startup when the
server or PC is rebooted?
A: Go to the "Services" panel. Right click on "Apache Tomcat", Properties. Startup Type = "Automatic"|
(Note: On my development computer, I prefer to leave mine on
"Manual" and manually start it.)
- Start Tomcat
Q: How do I Start the Tomcat Service?
A: Go to the "Services" panel. Right click on "Apache Tomcat",
click "Start"
- Stop Tomcat
Q: How do I Stop the Tomcat Service?
A: Go to the "Services" panel. Right click on "Apache Tomcat",
click "Stop"
Test your Install
- Open up a Browser
- Test the "Tomcat" installation
- Go to: http://localhost:8080 -
If this page doesn't come up you need to revisit the install. If you
still have problems I've seen some Firewalls cause issues.
Other URL alternatives that may work:
- Test your admin account & Password
- On the left side, under the section called "Administration", click on "Status".
User name: admin
Password: <enter your password>
(If you get the "Server Status" page then you entered the correct user/password.)
- Test the "Tomcat Manager" link
- Click on "Tomcat Manager"
- Since you have already authenticated as an "admin" you shouldn't be
prompted for a password unless you close your browser.
- You should see a list of Web Apps.
- Test the webapps that were installed in the installation:
Install your first Web Application
- Hello World Web Application - mytomcat-helloworld.zip
- Install "mytomcat-helloworld.war"
- Download this file: mytomcat-helloworld-war.zip
(Note: If you downloaded this tutorial to your local you have this
file already!)
- Unzip the file. There is one file in it called:
mytomcat-helloworld.war
- Copy the mytomcat-helloworld.war file to your
Tomcat Webapps directory.
(IE: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
)
- Tomcat monitors the "webapps" directory and will extract the
.war file's files and start the web application. If you desire
you can go to "Tomcat Manager" and see the new application.
You can also look at the new directory and files using Win Explorer
at:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\mytomcat-helloworld
- Note: If for some reason Tomcat doesn't auto install the .war
file then Stop/Start Tomcat.
- Test the new Web Application:
View the "Tomcat Documentation"
- http://localhost:8080 , click
"Tomcat Documentation" under Documentation.
- Click "3) First webapp" - "Application Developers Guide"
Finished
Other notes
- Tomcat
- Tomcat 5.5\conf\server.xml - Has the web server configuration
information like: Port #, etc...
- Tomcat 5.5\conf\tomcat-users.xml - The tomcat users &
passwords including the administrator you created.
- Tomcat Log files
- C:\Program Files\Apache Software Foundation\Tomcat 5.5\logs
- Terminology
- WAR - Web ARchive - this contains all of the files in a Web
Application. You can rename the .war file to a .zip file and see
the list of files. You can also use the Java command found in the
"bin" directory : jar -xvf sample.war