Building Apache Tomcat from source is very easy, and is the first step to
contributing to Tomcat. The complete and comprehensive instructions are
provided in the file BUILDING.txt.
The following is a quick step by step guide.

Building Apache Tomcat requires a Java 6 JDK to be installed and optionally
a Java 7 JDK installed in parallel with Java 6 one. The Java 7 JDK is only
required if you wish to build Tomcat with JSR-356 (Java WebSocket 1.1)
support.

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 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 involves downloading a number of libraries that it depends on.
It is strongly recommended to configure download area for those libraries.

By default the build is configured to download dependencies into directory
/usr/share/java. 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 is likely not appropriate for you to write there. On Windows this usually
corresponds to the C:\usr\share\java directory, unless Cygwin is
used.

The build is controlled by creating a
${tomcat.source}/build.properties file. It can be used to
redefine any property that is present in build.properties.default
and build.xml files. The build.properties file
does not exist by default. You have to create it.

If you have installed a Java 7 JDK and wish to build Tomcat with JSR-356
(Java WebSocket 1.1) support, set java.7.home property in
file ${tomcat.source}/build.properties to the location of
the Java 7 JDK installation.

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.

WARNING: Do not forget to create and configure
${tomcat.source}/build.properties file as described above
before running any Ant targets.

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.

Two Ant targets are provided as a convenience. The first one, named
ide-eclipse, downloads all binary dependencies and configures
Eclipse project in the root of the source tree. The created Eclipse project
targets a Java 6 JDK and skips WebSocket classes that cannot be compiled with
Java 6.

The second target, named ide-eclipse-websocket, creates directory
../tomcat-7.0.x-java7 and configures the second Eclipse project
there. This project targets a Java 7 JDK. This project does not have its own
source tree, but accesses a subset of the source tree of the first project,
compiling all WebSocket classes that were skipped.

cd ${tomcat.source}ant ide-eclipseant ide-eclipse-websocket

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.2 or later

In the Preferences dialog go to Java->Installed JREs
and add JDK 6 and JDK 7 there. Close the dialog.

Use File->Import command from menu and choose Existing Projects into Workspace.
From there choose the root directory of the Tomcat source tree (${tomcat.source})
and import the project located there. Import the second project as well,
if you have created it (../tomcat-7.0.x-java7).

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