tomcat源码导入eclipse

1. 获取源代码

   方式一:从官网http://tomcat.apache.org/download-70.cgi 直接下载,官网提供了Binary 和 Source Code两种下载方式,要研究tomcat源代码,选择最下面的source code 方式下载

   方式二:利用svn获取源代码,先安装svn,再新建目录tomcat7, 接着在目录里用 svn执行以下命令  

  svn co http://svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_35/ ./   下载源码

2. 将源码导入eclipse

  源码下载下来以后,请参考 tomcat官网 http://tomcat.apache.org/tomcat-7.0-doc/building.html 中详细的源码导入步骤,这是最好的文档。

    tomcat的源码是利用ant来创建和管理的。先安装ant,再执行ant ide-eclipse,该命令执行成功后,会在tomcat7目录下生产.project和.classpath两个文件,即成为eclipse工程了。这样你就可以将tomcat源码导入eclipse了(通过General--》Exisiting Projects into Workspace 选择ant 编译好的tomcat源码就可)
  
 tomcat源码导入 eclipse 以后可能会遇到 jdk版本或jar包(junit 等jar包)问题(按照官网导入,一般不会缺少jar包),自行解决jdk版本冲突后
 
  导入成功后如有问题 可以把examples 文件夹删除
3. 启动tomcat
  运行tomcat:找到tomcat的启动主类org.apache.catalina.startup包下的Bootstrap类,右击->“Run AS”->"Run Configurations",在Arguments窗口中做如下设置:
    在Program arguments中写入:start
    在VM arguments中写入:-Dcatalina.home="F:project omcatapache-tomcat-6.0.18-srcoutputuild" 。如下图所示:



  然后运行,可以看到tomcat启动成功,如下图所示:



  (5)停止tomcat:跟上面步骤一样,在Program arguments中写入:stop,点击运行。即可停止tomcat。
 
 
tomcat 源码导入成功后 ,就可以通过debug 一步一步的了tomcat的运行机制
 
------------------------------
tomcat 导入eclipse 成功以后 ,启动可能遇到问题
  错误:无法加载主类 org.apache.catalina.startup.Bootstrap
解决办法:检查eclipse导入的jar包是否正确 
 

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

TOMCAT_LIBS_BASE  tomcat源码中 build.properties 文件设置的 
base.path 位置
ANT_HOME the base path of Ant 1.8.1 or later

然后再启动 即可,不需要手动添加其他 jar包
 
原文地址:https://www.cnblogs.com/yidaxia/p/3997148.html