# Apache Tomcat 7

Version 7.0.4, Oct 14 2010

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/Native
- 24) Virtual Hosting
- 25) Advanced IO
- 26) Additional Components
- 27) Mavenized
- 28) Security Considerations

Reference

- Release Notes
- Configuration
- Tomcat Javadocs
- Servlet Javadocs
- JSP 2.2 Javadocs
- EL 2.2 Javadocs
- JK 1.2 Documentation

Apache Tomcat Development

- Building
- Changelog
- Status
- Developers
- Architecture
- Functional Specs.

# Building Tomcat

Table of Contents

> - Introduction
> - Download a Java Development Kit (JDK) 1.6 or later
> - Install Apache Ant 1.8.1 or later
> - Checkout or obtain the source code for Tomcat 7.0
> - Building Tomcat
> - Building with Eclipse
> - Building with other IDEs

Introduction

> Building Apache Tomcat from source is very easy, and is the first step to contributing to Tomcat. The following is a step by step guide.

Download a Java Development Kit (JDK) 1.6 or later

> Tomcat requires a JDK (version 1.6 or later) to be installed.
> 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.8.1 or later

> Download a binary distribution of Ant 1.8.1 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.8.x`). For the remainder of this guide, the symbolic name `${ant.home}` is used to refer to the full pathname of the Ant installation directory directory.

> IMPORTANT: 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 7.0

> Tomcat SVN repository URL: http://svn.apache.org/repos/asf/tomcat/trunk/

> Tomcat source packages: http://tomcat.apache.org/download-70.cgi.

> Checkout the source using SVN, 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 to build Tomcat:
> `
> cd ${tomcat.source}
> ant
> `

> NOTE: Users accessing the Internet through a proxy must use a properties file to indicate to Ant the proxy configuration. Read below for details.

> WARNING: Running this command will download binary binaries to the `/usr/share/java` directory by default. Make sure this is appropriate to do so on your computer. On Windows, this usually corresponds to the `C:\usr\share\java` directory, unless Cygwin is used. Read below to customize the directory used to download the binaries.

> 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=/usr/share/java
> `

> 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.

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: 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.

> Sample Eclipse project files and launch targets are provided in the `res/ide-support/eclipse` directory of the source tree. The instructions below will automatically copy these into the required locations.

> An Ant target is provided as a convenience to download all binary dependencies, and to create the Eclipse project and classpath files in the root of the source tree.
> `
> cd ${tomcat.source}
> ant ide-eclipse
> `

> Start Eclipse and create a new Workspace.

> Open the Preferences dialog and then select Java->Build Path->Classpath Variables to add two new Classpath Variables:

> TOMCAT_LIBS_BASE | The same location as the `base.path` setting in `build.properties`, where the binary dependencies have been downloaded
> ANT_HOME | the base path of Ant 1.8.1 or later

> Use File->Import and choose Existing Projects into Workspace. From there choose the root directory of the Tomcat source tree (`${tomcat.source}`) and import the Tomcat project located there.

> `start-tomcat` and `stop-tomcat` launch configurations are provided in `res/ide-support/eclipse` and will be available in the Run->Run Configurations dialog. Use these to start and stop Tomcat from Eclipse.
> If you want to configure these yourself (or are using a different IDE) then use `org.apache.catalina.startup.Bootstrap` as the main class, `start`/`stop` etc. as program arguments, and specify `-Dcatalina.home=...` (with the name of your build directory) as VM arguments.

> Tweaking a few formatting preferences will make it much easier to keep consistent with Tomcat coding conventions (and have your contributions accepted):

> Java -> Code Style -> Formatter -> Edit... | Tab policy: Spaces only Tab and Indentation size: 4
> General -> Editors -> Text Editors | Displayed tab width: 2 Insert spaces for tabs Show whitespace characters (optional)
> XML -> XML Files -> Editor | Indent using spaces Indentation size: 2
> Ant -> Editor -> Formatter | Tab size: 2 Use tab character instead of spaces: unchecked

Building with other IDEs

> The same general approach should work for most IDEs; it has been reported to work in IntelliJ IDEA, for example.

Copyright © 1999-2010, Apache Software Foundation