1,Tomcat6 源文件目录树结构

目录结构如下图:

Tomcat6源代码分析-构建tomcat

目录:

/bin 存放脚本文件,包括启动tomcat以及关闭tomcat等功能的bat,sh脚本。

/conf 存放tomcat的xml配置文件和properties配置文件。

/java java源代码放置到这个目录。

/native tomcat的native-connector工程放置的目录,是一个vc60工程。

/res ini文件及其它的一些静态资源文件可以放在res目录,以及生成可执行文件的nsis脚本。

/test 放置测试文件,项目

/webapps 放置tomcat的web工程文件

文件:

/build.properties.default 构建工程的属性文件

/build.xml ant 构建文件

/dist.xml 生成目标的构建文件

/extras.xml 扩展的构建文件

/其他 其他为说明文件

2,如何构建Tomcat6

(0)下载安装jdk1.5或者以上版本,设置JAVA_HOME环境变量指向JDK的安装目录。如果已经安装jdk,跳转到步骤1。

(1)安装apache ant 1.6.x。如果已经安装,请跳转到步骤2.下载apache

http://ant.apache.org/bindownload.cgi 。安装。

*创建ANT_HOME 环境变量,指向ant的安装目录 ${ant.home}.

* 在系统PATH环境变量中添加${ant.home}/bin .

(2)构建 Tomcat 6.0

(2.1)获取 Tomcat 6.0的源代码

* Tomcat SVN repository URL:

http://svn.apache.org/repos/asf/tomcat/tc6.0.x/

* Download a source package from:

http://tomcat.apache.org/download-60.cgi

* Checkout the source using SVN, selecting the desired version or

branch (current development source is at

http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk/), or

unpack the source package. The location where the source has been

placed will be referred as ${tomcat.source}.

(2.2) 构建

* Go to that directory, and do:

cd ${tomcat.source}

ant download

ant

* NOTE: Users accessing the Internet through a proxy must use a properties

file to indicate to Ant the proxy configuration. Read below.

* WARNING: Running this command will download binaries to the /usr/share/java

directory. Make sure this is appropriate to do 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

(3) Updating sources

It is recommended that you regularly update the downloaded Tomcat 6 sources

using your SVN client.

(4) Rebuilds

For a quick rebuild of only modified code you can use:

cd ${tomcat.source}

ant

(5) Building the servlet and jsp API documentation

The documentation can be easly built:

cd ${tomcat.source}

ant -f dist.xml dist-javadoc

(6) Building the extras (commons-logging, webservices etc.).

cd ${tomcat.source}

ant -f extras.xml

(7) Building a release running tests:

cd ${tomcat.source}

ant -f dist.xml release

3,build.xml解析

Build.xml是一个标准的ant的构建文件,通过此文件,可以构建tomcat工程。大纲结构如下:

Tomcat6源代码分析-构建tomcat

分析:

1,Tomcat工程的默认目标是deploy。

2,在工程的开头,首先指定构建文件的属性文件和属性。属性文件为build.properties.

3, download目标作用为下载tomcat编译依赖的库文件等。它依赖于如下几个目标。

Tomcat6源代码分析-构建tomcat

setproxy,proxyflags目标任务是设置网络代理,testexit,downloadgz,downloadzip, downloadfile这几个目标共同完成下载依赖文件的任务。Build-tomcat-dbcp,build-jasper-jdt作用是编译下载的依赖文件。

4,deploy目标作用生成/output/classes,和/output/build目录,编译java源代码生成class文件存放到classes目录,部署tomcat在build目录。

相关文章: