DekGenius.com
Previous Section  < Day Day Up >  Next Section

Recipe 11.2 Starting Tomcat

11.2.1 Problem

You want to get Tomcat running.

11.2.2 Solution

Set the JAVA_HOME and CATALINA_HOME environment variables, change directories to Tomcat's bin directory, and type startup in Windows or run startup.sh in Unix.

11.2.3 Discussion

Before starting Tomcat from the command line, you must set these two environment variables:


JAVA_HOME

You set this environment variable to the installation directory of Java, the parent directory of the Java bin directory; e.g., C:\jdk1.4 in Windows or /usr/java in Unix.


CATALINA_HOME

You set this environment variable to the installation directory of Tomcat, the parent directory of the Tomcat bin directory; e.g., C:\tomcat\jakarta-tomcat-5.0.19 in Windows.

You can set these environment variables from the command prompt (in Windows that's the DOS prompt; in Unix it's the shell) as in this example:

set JAVA_HOME=C:\jdk1.4

How you do this varies by operating system; for example, in the Unix tcsh shell, use setenv instead. After setting these environment variables, run Tomcat by changing directories to Tomcat's bin directory and typing startup in Windows, or running startup.sh in Unix. Note that in Windows, a new DOS window appears that displays initialization messages. To shut down Tomcat, type shutdown in Windows, or run shutdown.sh in Unix at the command line.

Now that you've gotten Tomcat running, open a browser, and navigate to http://localhost:8080, which should open Tomcat's Welcome page, as shown in Figure 11-1. The localhost part of this URL is what you use for web servers installed on your local machine (corresponding to an IP address of 127.0.0.1), and 8080 is the port number (web servers usually use port 80, but Tomcat uses 8080 to avoid conflicts with other servers).

Figure 11-1. The Tomcat 5.0.19 startup page
figs/ecb_1101.gif


When you store new .class files in the Tomcat directories or edit files such as the web.xml file you'll see later, you should stop Tomcat and restart it. Doing so makes sure Tomcat copies over your changes from its webapps directory to its work directory, which is what it actually serves documents from (there are ways to configure Tomcat so that you don't need to restart it this way, but that's beyond the scope of this book.


11.2.4 See Also

Recipe 11.1 on installing Tomcat; Chapter 1 in Tomcat: the Definitive Guide (O'Reilly); Chapter 4 in JavaServer Pages (O'Reilly); Chapter 9 in Eclipse (O'Reilly).

    Previous Section  < Day Day Up >  Next Section