最近在学习Java Web服务端架构,想从最原始的架构学起,于是选择了Servlet,而在学习Servlet必须用到Tomcat,于是想进一步深入了解Tomcat。Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。

1. 编译源码

  • 到apache官网或github搜索tomcat源码并下载,也可以直接点击此下载
  • 安装ant命令,sudo brew install ant
  • 进入tomcat目录,并执行ant
  • 等待编译成功,成功后目标文件默认输出到output目录下
  • 进入output/build,这是目录结构
drwxr-xr-x   9 starnet  staff  306 Apr  8 09:55 .
drwxr-xr-x   7 starnet  staff  238 Apr  8 09:56 ..
drwxr-xr-x  26 starnet  staff  884 Apr  8 09:54 bin
drwxr-xr-x  13 starnet  staff  442 Apr  8 09:55 conf
drwxr-xr-x  27 starnet  staff  918 Apr  8 09:54 lib
drwxr-xr-x   8 starnet  staff  272 Apr  8 09:55 logs
drwxr-xr-x   2 starnet  staff   68 Apr  8 09:54 temp
drwxr-xr-x   7 starnet  staff  238 Apr  8 09:54 webapps
drwxr-x---   3 starnet  staff  102 Apr  8 09:55 work
  • 执行./bin/startup.sh
bogon:build starnet$ ./bin/startup.sh 
Using CATALINA_BASE:   /Users/starnet/Projects/tomcat/output/build
Using CATALINA_HOME:   /Users/starnet/Projects/tomcat/output/build
Using CATALINA_TMPDIR: /Users/starnet/Projects/tomcat/output/build/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
Using CLASSPATH:       /Users/starnet/Projects/tomcat/output/build/bin/bootstrap.jar:/Users/starnet/Projects/tomcat/output/build/bin/tomcat-juli.jar
Tomcat started.
  • 点击此访问:http://localhost:8080,若能看到tomcat信息,那恭喜你,成功了.

2. 阅读源码

  • 安装Eclipse软件
  • 新建Java Project
  • 从File System进行import,选择tomcat源码目录
  • 确定导入