Software Development: Apache Tomcat

[article] [edit page] [discussion] [history]

From Humanitarian-FOSS Project Development Site

We will use Apache Tomcat as our webserver that implements the Java Servlet and JSP technologies. Be certain to download the current stable version of Tomcat 6.x. Since Tomcat is a Java application, it should run out of the box provided you have already installed Java on your system. However, there are a few details to be sure of:

  • It appears that you can run Tomcat as a daemon (Unix-based systems) or a Windows Service (Windows). I recommend doing neither. Just download either the ZIP or tar file for the binary installation and unpack. You will run Tomcat as an ordinary user process, starting and stopping it as needed.
  • Make sure to start Tomcat with the (Unix-based systems) or startup.bat (Windows) scripts, which are located in the bin directory of your installation. Likewise shut Tomcat down with or shutdown.bat.
  • Permissions. Tomcat looks for webapps, writes log files, etc., in various subdirectories of the environment variable CATALINA_HOME. If you do not set this yourself, then will set it to the installation directory for your Tomcat installation. Thus, you need to make sure that you have write permission on these directories.
  • You should configure Tomcat Manager so that once you have started Tomcat, you can start, stop, and reload web applications without restarting the server. See the "Configuring Manager Application Access" subsection of the Manager section of the on-line documentation. You want to follow the instructions for the "MemoryRealm."
  • Since we will use the JSTL in our projects, and we don't want to include a copy of it in every web app we write, you must install the Jakarta implementation of JSTL 1.1 into Tomcat itself. To do so:
    1. Download the Jakarta Taglibs implementation by following the "Downloads" link, then selecting "Standard 1.1 Taglib," and then download either the tar.gz or .zip binary distribution.
    2. Unpack the downloaded file and copy the two JAR files in the lib subdirectory to the lib subdirectory of your Tomcat installation.
    3. I recommend renaming the JAR files when you copy them to something like jakarta-taglibs-std-1.1-XXX.jar where XXX is the original name, so that it is clear what these JAR files are doing in your Tomcat installation.

    This JSTL implementation will be available to all web apps upon the next restart of Tomcat.

  • Using Tomcat on marlow: This takes a little bit of care, because we want to be sure that all students can run Tomcat without interfering with each other. Here is what you need to do to set things up:
    1. In $COMP342, create apps/apache-tomcat-6.0.18 and the following subdirectories: conf, logs, temp, webapps, and work.
    2. Copy /opt/apache-tomcat-6.0.18/conf/server.xml, /opt/apache-tomcat-6.0.18/conf/web.xml, and /opt/apache-tomcat-6.0.18/conf/tomcat-users.xml to your conf directory.
      1. Edit server.xml as follows. Search for the string 8080; it should appear in a block that looks like:
        <Connector port="8080" protocol="HTTP/1.1" 
                   redirectPort="8443" />

        Ask Norman what number to use for the port instead of 8080. This is important; if two users attempt to run Tomcat and both have it talking to port 8080, everybody is likely to be unhappy.

      2. Edit tomcat-users.xml to add a better username and password to the manager account if you like.
    3. Edit your $HOME/.bashrc to set the following two environment variables:
      export JAVA_HOME=/opt/jdk1.6.0_07
      export CATALINA_BASE=$HOME/comp342/apache-tomcat-6.0.18

      Here I am assuming that your $COMP342 directory is in fact $HOME/comp342; change the definition of CATALINA_BASE accordingly if this is not the case.

    4. You can now start and stop Tomcat with the commands start_tomcat and stop_tomcat. If those commands are not found, edit your .bashrc file to put /usr/local/bin in your path (see above).
Personal tools