This is a brief "how-to" for installing Tomcat on a Windows PC.
Tomcat requires java in order to run. If your computer already has java installed, you can probably skip this step. However, make sure you have a recent version of java. Here I provide instructions for installing version 1.4.2 of the Java 2 Platform, Standard Edition (J2SE).
Tomcat will need to know where you have installed java. To do this, you will need to set the environment variable JAVA_HOME to C:\j2sdk1.4.2_01 (where you installed java).
Here are the steps for setting the environment variable on my computer (Windows XP Professional). The steps will probably be similar for other Windows computers.
JAVA_HOME
C:\j2sdk1.4.2_01
After setting the JAVA_HOME environment variable, you can install tomcat.
Here are the steps to see if Tomcat has been successfully installed
http://localhost:8080/
At this point, you should see the Tomcat home page, which is provided by the
Tomcat Web server running on your computer. Note: if your computer has an
internet name or an IP number, you may access your Tomcat server anywhere on
the internet by substituting localhost
with the full name or IP number.
To shut down your server and remove the Console window, select "Stop Tomcat" in the same menu of where you selected "Stop Tomcat".
CLASSPATH
Since servlets and JSP are not part of the Java 2 platform,
standard edition, you have to identify the servlet classes to the compiler. The
server already knows about the servlet classes, but the compiler
(i.e., javac
)
you use for development probably doesn't. So, if you don't set your CLASSPATH
,
attempts to compile servlets, tag libraries, or other classes that use the
servlet and JSP APIs will fail with error messages about unknown classes. Here
are the standard Tomcat locations:
Tomcat 4: c:\tomcat4\common\lib\servlet.jar
in addition to the servlet JAR file, you also need to put your development
directory in the CLASSPATH
.
Although this is not necessary for simple packageless servlets, once you gain
experience you will almost certainly use packages. Compiling a file that is in
a package and that uses another class in the same package requires the CLASSPATH
to
include the directory that is at the top of the package hierarchy. In this
case, that's the development directory I just discussed. Forgetting this setting is perhaps the most common mistake
made by beginning servlet programmers!
Finally, you should include "." (the current directory) in the CLASSPATH
.
Otherwise, you will only be able to compile packageless classes that are in the
top-level development directory.
Here are two representative methods of setting the CLASSPATH
.
They assume that your development directory is C:\Servlets+JSP. Replace install_dir
with the actual base installation location of the server. Also, be sure to use
the appropriate case for the filenames, and enclose your pathnames in double
quotes if they contain spaces.
Note that these examples represent only one approach for
setting the CLASSPATH
.
Many Java integrated development environments have a global or project-specific
setting that accomplishes the same result. But these settings are totally
IDE-specific and won't be discussed here. Another alternative is to make a
script whereby -classpath
...
is automatically appended onto calls to javac
.
CLASSPATH
value from the previous bullet. The invoker servlet lets you run servlets without first
making changes to your Web application's deployment descriptor (i.e., the WEB-INF/web.xml
file). Instead, you just drop your servlet into WEB-INF/classes and use
the URL http://host/servlet/ServletName (or http://host/webAppName/servlet/ServletName
once you start using your own Web applications). The invoker servlet is
extremely convenient when you are learning and even when you are doing your
initial development. To enable the invoker servlet, uncomment the following servlet-mapping
element in c:\tomcat4\conf\web.xml. Also, do not confuse this Apache
Tomcat-specific web.xml file with the standard one that goes in the WEB-INF
directory of each Web application. Finally, remember to make a backup copy of
the original version of this file before you make the changes.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
Here are the steps for running the class examples discussed on the first day.
c:\ Tomcat4\webapps\webdir\WEB-INF\classes\HelloWorld.java
http://localhost:8080/webdir/servlet/HelloWorld
Note: this note is copied partly from http://facweb.cs.depaul.edu/cmiller/ect433/tomcatInstall.html
From someone who want to how to config tomcat, please refer to:
http://www.coreservlets.com/Apache-Tomcat-Tutorial/