Tomcat Installation

I am only going to explain the installation process in a basic way, I strongly advise that you check the latest documentation on how to Install Tomcat and the JVM. This way you will have the latest information as web site may become stale.

JVM Installation

Tomcat requires a Java Virtual Machine (JVM), you can obtain the JVM from Sun Microsystems. Just follow the documentation supplied with the software for your particular operating system.

Once you have installed the JVM (you require version 1.5 or greater)

Check JVM version

C:\>java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

 

Tomcat version 5.5 and 6 have a Java compiler (the Eclipse JDT Java Compiler) package along with them. This is used to compile JSP pages, hence you only need to download the Java JRE version.

Tomcat Installation

First you need to obtain the Tomcat package, so navigate to tomcat.apache.org and obtain the package for your particular operating system. Download the core distribution if you are installation a new version, if you are upgrading then you can download the deployer version.

For testing and learning I have obtained the windows version which makes installation a breeze. One word of warning change the default installation directory, by default the default directory contains spaces which bad, so change it to something like c:>tomcat or c:>tomcat6, you will thank me later when we get into creating JSPs.

There are several ways to start Tomcat, either running the tomcat6.exe file or starting it as a windows service.

Once you have started Tomcat you can test it by point your browser to http://localhost:8080/ (if you installed Tomcat locally), you should get the tomcat default page come up.

If you have a problem starting Tomcat on the default port number because it is in use, then edit the %CATLINA_HOME%\conf\server.xml file and change the port number to something that is available.

Change default port number

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

change to

<Connector port="8181" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

Note: you can use any port that is available

Tomcat Installation Directory

The Tomcat directory should look like below after the installation.

bin contains the scripts that start/stop Tomcat, it also has a pre-compiler for JSP pages that can improve startup time and first-time response.
conf contains the configuration files for Tomcat. These include general server config files, default user list for file-based authentication and security for Web Application and a global configuration file
logs contains the server logs
lib contains all the JAR files used by Tomcat
webapps contains all the Web application provided with Tomcat by default, user developed Web application will be deployed in this directory
work contains temporary files, precompiled JSP pages and other intermediate files.

Installing APR

The Apache Portable Runtime (APR) is an optional component that can be installed with Tomcat, it improves stability and performance, especially when Tomcat is used to connect to a native Web server like Apache.

Sometimes you will see the below message in the catalina log file in the log directory

   INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.........

it is because the APR library is missing at Tomcat startup time. You can download the latest version library from tomcat.apache.org. Read the instructions on how to install the library for your particular O/S. Once installed you should see the below line in the catalina log file

   INFO: Loaded Apache Tomcat Native library <version>

We go into detail regarding this library when we discuss the APR connector, which is an HTTP connector for Tomcat developed using APR.

Troubleshooting Tips

You can run Tomcat from a dos shell or a commandline, if for instance when starting Tomcat it stops immediately, this can produce some output to the display that otherwise would have been lost.

Running from dos shell or commandline

$CATALINA_HOME/bin/catalina.sh run

%CATALINA_HOME\bin\catalina run

Tomcat requires Java SE 5 or later, so if you get the below message then you need to upgrade you version of Java, you could have your JAVA_HOME pointing to the wrong version

Java version problem Exception in thread "main"
  java.lang.UnsupportedClassVersionError:
  org/apache/catalina/startup/Bootstrap (Unsupported major.minor version 49.0)

A common error especially if you have installed Tomcat on your laptop to play around with, is the port already in use problem. By default Tomcat uses port 8080, you can use the "netstat" command (both Unix and Windows uses netstat) to display the port numbers already in use. You have two choices sort out what is already using port 8080 or change the default port number Tomcat uses, use the below file to do this

Change Tomcat's default port number

$CATALINA_HOME\conf\server.xml

Note: see above regarding the line that you need to change.

The last common error is that you have setup the Tomcat server in your companies environment perhaps on a old server, thus firewall's may be blocking HTTP to the Tomcat server, you will need to contact your local support team to resolve this issue.