Installing Jakarta Tomcat

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Chapter 21.  Servlets


Jakarta Tomcat is availableat no cost from the Apache Web site at http://www.apache.org/.

The link for Tomcat 4.0.4 is http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.4/bin/.

Choose a release that is right for your needs. If you are running Java 1.4, the following self-extracting .exe file will becorrect for you:

 jakarta-tomcat-4.0.4-LE-jdk14.exe 

Caution

graphics/01icon17.gif

As new versions of Tomcat are released, the links that lead to them will differ from those shown previously. In these cases, you will need to go to the http://jakarta.apache.org/ Web site and navigate to the newest release.


You will then be prompted to enter the location where you want this .exe file stored. Next, open Windows Explorer and double-click the name of the .exe file. This will open an installation wizard that will guide you through the installation. After you answer a few questions, you will be told that the installation is complete.

If you are running under Unix, you can download the tar version and follow the instructions on the Apache Web site on how to install Tomcat on your machine.

Caution

graphics/01icon17.gif

Vendor Web sites change from time to time. If the previous steps don't work exactly, look for similar links at each step, and you should be able to succeed in getting Tomcat installed.


Starting Tomcat

You start Tomcat by opening a command window and typing the following command.

 java -jar -Duser.dir="C:\Program Files\Apache Tomcat 4.0"  "C:\Program Files\Apache Tomcat 4.0\bin\bootstrap.jar" start 

Tomcat will output several lines of responses like these, which provide feedback that the server is really running.

 Starting service Tomcat-Standalone  Apache Tomcat/4.0.4  Starting service Tomcat-Apache  Apache Tomcat/4.0.4 

On some operating systems, the installation script places some shortcuts in your file system to make the task of starting Tomcat easier. On our test machine, Windows XP, these shortcuts were placed in a directory called:

 C:\Documents and Settings\Your Name\Start Menu\Programs\Apache Tomcat 4.0 

Your Name will be replaced by the login name of the machine that you are using.

Another link on that page opens a browser that contains the root page for the copy of the Tomcat documentation that is stored on your local hard drive. Figure 21.2 shows this page.

Figure 21.2. The Tomcat documentation provides detailed instructions about how to get the server and keep it running.

graphics/21fig02.gif

Note

graphics/01icon18.gif

You can find answers to many of your questions with these pages, so it would be a good idea to bookmark the root page in your browser.


Most of the work that you will do with Tomcat will involve four of the directories located under the root Tomcat directory. These directories are

  • C:\Program Files\Apache Tomcat 4.0\bin This directory contains scripts to perform functions such as startup, shutdown, and so on. Under Windows, these scripts are .bat files, and under Unix, they are .sh files.

  • C:\Program Files\Apache Tomcat 4.0\conf This directory contains configuration files, which control the behavior of the server. Most of these files are in XML format. The most important file in here is called server.xml, the main configuration file for the server.

  • C:\Program Files\Apache Tomcat 4.0\logs This directory contains the logs that are created by the Tomcat server. You inspect these logs to discover clues about why certain problems are occurring with the installation and/or your programs.

  • C:\Program Files\Apache Tomcat 4.0\webapps This directory is where you put your programs. Web servers don't like to access files all over your computer because of the security risks. They prefer to allow clients to access only files that are stored in one place and its subdirectories.

Testing the Installation

After you have finished the installation, you will want to test the server using servlets provided by Apache before writing your own. The reason for this is that any problem you have running their servlets is certainly a configuration problem. If you run your own servlets without first verifying that the installation is correct, the problem could be either in the installation or with your servlet.

Testing the installation is easy. First, start Tomcat by following the procedure described previously. Next, type the following command in a browser address box:

 http://localhost:8080 

You should immediately see a screen that looks like Figure 21.3.

Figure 21.3. The Tomcat localhost home page will display when the server is running properly.

graphics/21fig03.gif

If you do not see this page immediately, the most likely reason is that you have another program listening to port 8080. In that case, edit the file called server.xml in the C:\Program Files\Apache Tomcat 4.0\conf directory. Look for the following lines:

    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->  <Connector          className="org.apache.catalina.connector.http.HttpConnector"                 port="8080" minProcessors="5" maxProcessors="75"                 enableLookups="true" redirectPort="8443"                 acceptCount="10" debug="0" connectionTimeout="60000"/> 

Edit the fourth line and change it to some value more than 1024, like 1776. It will look like this:

 <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->   <Connector className=            "org.apache.catalina.connector.http.HttpConnector"              port="1776" minProcessors="5" maxProcessors="75"              enableLookups="true" redirectPort="8443"              acceptCount="10" debug="0" connectionTimeout="60000"/> 

Save this file and restart the Tomcat server. Repeat the test by opening a browser, but this time type

 http://localhost:1776 

If this doesn't open the magic Web page shown in Figure 21.3, consult the troubleshooting documentation that Tomcat installed on your hard drive.

Note

graphics/01icon18.gif

This chapter uses port 1776 for all the examples. The reason for this is that port 8080, the default Tomcat port, was already in use on our test machine.



       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net