Apache Tomcat

Overview

Tomcat is an apache.org project that provides a Java based web server that excels at running Java based web applications. In particular, one has a choice of Java ServerPages (JSP) or Java Servlets.

Terminology

The web applications that one builds are commonly referred to as a Context.

Directories and Files

The root of the Tomcat installation is referred to as $CATALINA_HOME.
Tomcat can be configured for multiple instances by defining $CATALINA_BASE. These two environment variables are one in the same by default.

Here are some key tomcat directors:

  • /bin - shell scripts to start/stop tomcat
  • /conf - this is where configuration files live and related DTD’s. The most important file is server.xml which is the main configuration file for the container.
  • /logs - Log files
  • /webapps - Where the web application parts go.

Installation

This installation is for Ubuntu 9.10.

packages

  • tomcat6 - the primary package which has the following dependencies:
The following extra packages will be installed:
  jsvc libcommons-collections-java libcommons-daemon-java libcommons-dbcp-java libcommons-pool-java
  libecj-java libservlet2.5-java libtomcat6-java tomcat6-common

and these Suggested packages:

  java-virtual-machine classpath-doc ecj libecj-java-gcj tomcat6-docs tomcat6-admin tomcat6-examples

I will install the last three suggested packages: tomcat6-docs tomcat6-admin tomcat6-examples.

Permissions

/etc/tomcat6 permissions [optional]

Give tomcat6 user (created during install) full permissions to /etc/tomcat6

sudo chgrp -R tomcat6 /etc/tomcat6
sudo chmod -R g+w /etc/tomcat6 

manager application

In order to access this area, one must have a user account with a manager role. One can create this by editing the /etc/tomcat6/tomcat-users.xml file.1

Example Application

Application Root

  • /var/lib/tomcat6/webapps - this the root directory for web applications in general. Within the directory we create a ExampleServlet/ directory for this example Servlet.

Structure within

  • index.html - regular HTML page used to access the servlet
  • WEB-INF/ - This directory is essential the the servlet. It contains:
    • web.xml - the configuration file for the servlet
    • classes/ - the directory where the compiled (and source if one likes) live.

CLASSPATH

In order to compile a servlet class one needs to make sure the servlet api jar is in their CLASSPATH:

export CLASSPATH=".:/usr/share/tomcat6/lib/servlet-api.jar"

Foot Notes

1 Make sure to uncomment the tomcat user configuration as it may be commented (html comment style) by default.

My tags:
 
Popular tags:
 
Powered by MojoMojo