The Apache Tomcat 5.5 Servlet/JSP Container - Building Tomcat
Author: Remy Maucherat

| # The Apache Tomcat 5.5 Servlet/JSP Container |

Links Docs Home FAQ User Guide 1) Introduction 2) Setup 3) First webapp 4) Deployer 5) Manager 6) Realms and AAA 7) Security Manager 8) JNDI Resources 9) JDBC DataSources 10) Classloading 11) JSPs 12) SSL 13) SSI 14) CGI 15) Proxy Support 16) MBean Descriptor 17) Default Servlet 18) Clustering 19) Load Balancer 20) Connectors 21) Monitoring and Management 22) Logging 23) APR 24) Virtual Hosting Reference Release Notes Apache Tomcat Configuration JK 1.2 Documentation Servlet API Javadocs JSP API Javadocs Apache Tomcat Development Building Changelog Status Developers Functional Specs. Apache Tomcat Javadocs Apache Jasper Javadocs Architecture | # The Apache Tomcat 5.5 Servlet/JSP Container ## Building Tomcat
Table of Contents
README Introduction Download and install a Java Development Kit 1.4.x or later Install Apache Ant 1.6.2 or later Checkout or obtain the source code for Tomcat 5.5 Building Tomcat Updating and rebuilding Tomcat sources Building with Eclipse Building with other IDEs
README
This document duplicates some of the information from the BUILDING.txt file included in every Tomcat distribution. You may want to consult both.
Introduction
Building Tomcat from SVN is very easy, and is the first step to contributing to Tomcat. The following is a step by step TODO list.
Download and install a Java Development Kit 1.4.x or later
The default distribution of Tomcat 5.5.x requires a 5.0 or later JDK. Tomcat can be built using a 1.4.x JDK but you will need to copy the contents of the compat directory (created by the build process) to your build directory before Tomcat will start. The Sun JDK can be downloaded here. IMPORTANT: Set an environment variable JAVA_HOME to the pathname of the directory into which you installed the JDK release.
Install Apache Ant 1.6.2 or later
Download a binary distribution of Ant 1.6.2 or later from here. Unpack the binary distribution into a convenient location so that the Ant release resides in its own directory (conventionally named "apache-ant-1.6.x"). For the purposes of the remainder of this document, the symbolic name "${ant.home}" is used to refer to the full pathname of the release directory. Create an ANT_HOME environment variable to point the directory ${ant.home}, and modify the PATH environment variable to include directory "${ant.home}/bin" in its list. This makes the "ant" command line script available, which will be used to actually perform the build.
Checkout or obtain the source code for Tomcat 5.5
Tomcat 5.5 SVN repository URL: http://svn.apache.org/repos/asf/tomcat/tc5.5.x/trunk/ Tomcat 5.5 source packages: http://tomcat.apache.org/download-55.cgi. Checkout the source using SVN, selecting a tag for released version or trunk for the current development code, or download and unpack a source package. For the remainder of this guide, the symbolic name `${tomcat.source}` is used to refer to the location where the source has been placed.
Building Tomcat
Use the following commands: `cd ${tomcat.source}/build ant download ant` WARNING: Running "ant download" command will download libraries required to build Tomcat to the `/usr/share/java` directory by default. On a typical Linux or MacOX system, an ordinary user will not have access to write to this directory, and, even if you do, it may not be appropriate for you to write there. On Windows this usually corresponds to the `C:\usr\share\java` directory, unless Cygwin is used. Read below to learn how to customize the directory used to download the binaries. NOTE: Users accessing the Internet through a proxy must use a properties file to indicate to Ant the proxy configuration. Read below. The build can be controlled by creating a ${tomcat.source}/build.properties file, and adding the following content to it: `# ----- Proxy setup ----- # Uncomment if using a proxy server. #proxy.host=proxy.domain #proxy.port=8080 #proxy.use=on # ----- Default Base Path for Dependent Packages ----- # Replace this path with the directory path where # dependencies binaries should be downloaded. base.path=/home/me/some-place-to-download-to` Once the build has completed successfully, a usable Tomcat installation will have been produced in the `${tomcat.source}/output/build` directory, and can be started and stopped with the usual scripts. See `BUILDING.txt` file in Tomcat source code for additional build options.
Updating and rebuilding Tomcat sources
It is recommended to regularly update the downloaded Tomcat 5.5 sources. To do this, execute `svn update` command with your Subversion client. For a quick rebuild of only modified code you can use: `cd ${tomcat.source}/build ant`
Building with Eclipse
> Important: This is not a supported means of building Tomcat; this information is provided without warranty :-). The only supported means of building Tomcat is with the "ant build" described above. However, some developers like to work on Java code with a Java IDE, and the following steps have been used by some developers. Note that you must complete all the above steps to fetch dependent libraries and build some JAR files the first time. After you have completed the above steps, you can set up an Eclipse project. Note that this will not let you build everything under Eclipse; the build process requires use of Ant for the many stages that aren't simple Java compilations. However, it will allow you to view and edit the Java code, get warnings, reformat code, perform refactorings, run Tomcat under the IDE, and so on. Use Windows->Preferences and then Java->Build Path->Classpath Variables to add two new Classpath variables:
> TOMCAT_LIBS_BASE | the base path where the binary dependencies have been downloaded
> ANT_HOME | the base path of Ant 1.6.2 or later
There are two files in the root directory, `eclipse.classpath` and `eclipse.project`. Create their copies with new names, `.classpath` and `.project` respectively. Use File->Import and chose "Existing Projects into Workspace". From there import the root directory where you have checked out tomcat. Eclipse .project and .classpath files provided in the root directory of tomcat repository should allow Eclipse to find all source trees and jars, and hopefully compile without problems. Note that these files assume you are using Eclipse with a 5.0 or later JDK. To run Tomcat without a special IDE plug-in, you can simply use Run->Run... enter "org.apache.catalina.startup.Catalina" as the main class, "start" as program arguments, and "-Dcatalina.home=..." (with the name of your build directory) as VM arguments.
Building with other IDEs
The same caveats apply as for Eclipse, above. The same general idea should work in most IDEs; it has been reported to work in Idea, for example.
Copyright © 1999-2012, Apache Software Foundation