作JAVA web开发的童鞋,对于tomcat都不陌生。使用的时候,也都是修改一些配置文件,遇到问题google。我也不能免俗。前面再看webx的东西,一直对于整个web的启动框架比较困惑,所以决定开始学习tomcat的原理,当然看源码是最不容易出错的途径了。
学习源码,先从编译开始。
安装JDK6
一定要设置JAVA_HOME环境变量
安装Apache Ant 1.8.1 or later
设置环境变量ANT_HOME,并在PATH里面加入$ANT_HOME/bin
下载源码
http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk/
或者 git clone https://github.com/remind/tomcat70
或者 git clone https://github.com/remind/tomcat70
源码目录标记为${tomcat.source}
编译源码
编译之前先拷贝${tomcat.source}下面的build.properties.default文件为build.properties,并且修改里面的base.path为你本地的一个存在的目录,这个目录最好不要在${tomcat.source}下面。然后执行下面的命令
cd ${tomcat.source}
ant ide-eclipse
导入代码到eclipse
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 |
运行
run as