Setting Up the Apache Tomcat Server
Tomcat is a fully functional implementation of servlets and JavaServer Pages (JSP). It includes a Web server, so it can be used as a standalone test container for servlets and JSPs. Tomcat can also be specified as the handler for JSP and servlet requests received by popular Web servers such as the Apache Software Foundation's Apache HTTP server or Microsoft's Internet Information Services (IIS). Tomcat is also integrated into the Java 2 Enterprise Edition reference implementation from Sun Microsystems.
The most recent release of Tomcat at the time of printing (version 5.0.25) can be downloaded from
apache.towardex.com/jakarta/tomcat-5/v5.0.25/bin/
where there are several archive files. The complete Tomcat implementation is contained in the files that begin with the name jakarta-tomcat-5.0.25. Apache provides zip, exe, tar and compressed tar files.
Following the steps below to install Tomcat:
- Download jakarta-tomcat-5.0.25.zip (or the version appropriate for your system) to your hard disk.
- Use a file extractor tool (such as WinZip, available at www.winzip.com) to extract the content of jakarta-tomcat-5.0.25.zip to the C: drive. This will create a directory named jakarta-tomcat-5.0.25.
For Tomcat to work correctly, you must define environment variables JAVA_HOME and CATALINA_HOME. JAVA_HOME should point to the directory containing your Java installation (ours is C:Program FilesJavajdk1.5.0), and CATALINA_HOME should point to the directory that contains Tomcat (ours is C:jakarta-tomcat-5.0.25). To define these variables on Windows,
- Right click on the My Computer icon on your desktop and select Properties from the menu. The System Properties dialog appears.
- Select the Advanced tab at the top of the System Properties dialog. Click the Environment Variables button to display the Environment Variables dialog.
- Click the New button under the User variables box. This will cause the Edit User Variable dialog to appear.
- Enter JAVA_HOME for Variable name and C:Program FilesJavajdk1.5.0 for Variable value. Click the OK button to complete the setting of the JAVA_HOME variable. This will return to the Environment Variables dialog.
- Click the New button under the User variables box. This will cause the Edit User Variable dialog to appear.
- Enter CATALINA_HOME for Variable name and C:jakarta-tomcat-5.0.25 for Variable value. Click the OK button to complete the setting of the CATALINA_HOME variable. This will return to the Environment Variables dialog.
- Click the OK buttons to close the Environment Variables and System Properties dialogs.
Error-Prevention Tip 26.1
On some platforms you may need to restart your computer for the new environment variables to take effect. |
After setting the environment variables, you can start the Tomcat server. In a command prompt (or shell), change to the bin directory in jakarta-tomcat-5.0.25. In this directory are the files startup.bat, shutdown.bat, startup.sh and shutdown.sh, for starting and stopping the Tomcat server on Windows and UNIX/Linux/Mac OS X, respectively. To start the server, type
startup
This launches the Tomcat server, which executes on TCP port 8080 to prevent conflicts with standard Web servers that typically execute on TCP port 80. [ Note: If port 8080 is already in use by another application, you can change the port number for Tomcat by modifying the file server.xml, which is located in the Tomcat installation directory's conf directory. To do so, edit line 92 of server.xml (which contains the text <Connector port="8080") and replace "8080" with the port number you want to use.] To verify that Tomcat is executing and can respond to requests, open your Web browser and enter the URL
http://localhost:8080/
[ Note : If you changed the port number, use the new port number you specified.] This should display the Tomcat documentation home page (Fig. 26.6). The host localhost indicates to the Web browser that it should request the home page from the Tomcat server on the local computer.
Figure 26.6. Tomcat documentation home page. Copyright © 2000-2004 The Apache Software Foundation (http://www.apache.org/). All rights reserved.
(This item is displayed on page 1247 in the print version)
Error-Prevention Tip 26.2
If the host name localhost does not work on your computer, substitute the IP address 127.0.0.1 instead. |
To shut down the Tomcat server, issue the command
shutdown
from the command prompt (or shell) that starts the Tomcat server.