一直在用tomcat,想了解一下tocmat的原理,下面给大家展示如何将源码导入eclipse;

版本apache-tomcat-6.0.39

这里官方教程地址 http://tomcat.apache.org/tomcat-6.0-doc/building.html;

我的整个导入流程也是基于官方的教程,毕竟网上的说法太杂乱了。

准备资源:

tomcat6源码:http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.39/src/;

ant1.8.0: http://archive.apache.org/dist/ant/binaries/  ;


第一步,配置好ant的环境变量

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.


ANT_HOME=D:\apache-ant-1.8.0

CLASSPATH=%ANT_HOME%\lib;

PATH=%ANT_HOME%\bin;


第二步,下载tomcat依赖包,编译tomcat源码


操作之前要对依赖包的存在放路径进行设置,

打开E:\apache-tomcat-6.0.39-src路径下的build.properties.default文件

设置base.path=D:/ant/tomcat_libs_base/

如果你使用的是http代理,那么请在 build.properties.default中添加如下配置

proxy.host=代理IP
proxy.port=代理端口
proxy.use=on

否则修改build.xml中

查找setproxy, 将if的值改为false  <target name="setproxy" depends="proxyflags" if="false">

然后开始运行命令

cd E:\apache-tomcat-6.0.39-src

ant download
ant



以上工作准备好后,就进入第三步,导入eclispe

将apache-tomcat-6.0.39-src文件夹下两个文件eclipse.classpath  eclipse.project另存为

.classpath 和.project.


Use Windows->Preferences and then Java->Build Path->Classpath Variables to add two new Classpath variables:

添加两个参数

TOMCAT_LIBS_BASE   值为D:/ant/tomcat_libs_base/

ANT_HOME 值为D:\apache-ant-1.8.0


Use File-> "Existing Projects into Workspace" 选择apache-tomcat-6.0.39-src目录导入即可。


导完项目之后,怎么让tomcat跑起来呢?


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.


其实很简单,点右键run as > run configurations  选择java application 再点右键 选择 new  出现如下图:


wKiom1VeqwnwyV2FAAGgEKlIYXc093.jpg


wKiom1Veq8riE3kQAAIDOQAzCYM657.jpg


wKiom1VeqwrCTusKAAWPqo0tP98313.jpg