Tomcat详解系列(3) - 源码分析准备和分析入口

Tomcat - 源码分析准备和分析入口

上文我们介绍了Tomcat的架构设计,接下来我们便可以下载源码以及寻找源码入口了。@pdai

源代码下载和编译

首先是去官网下载Tomcat的源代码和二进制安装包,我这里分析最新的Tomcat9.0.39稳定版本https://tomcat.apache.org/download-90.cgi

下载二进制包和源码

下载二进制包的主要目的在于,让我们回顾一下包中的内容;其次,在我们后面通过源码包编译后,以方便和二进制包进行对比。

  • 下载两个包

  • 查看二进制包中主要模块

编译源码

  • 导入IDEA

  • 使用ant编译

理解编译后模块

这里有两点要注意下:第一:在编译完之后,编译输出到哪里了呢?第二:编译后的结果是不是和我们下载的二进制文件对的上呢?

  • 编译的输出在哪里

  • 编译的输出结果是否对的上,很显然和上面的二进制包一致

从启动脚本定位Tomcat源码入口

好了,到这里我们基本上已经有准备好代码了,接下来便是寻找代码入口了。@pdai

startup.bat

当我们初学tomcat的时候, 肯定先要学习怎样启动tomcat. 在tomcat的bin目录下有两个启动tomcat的文件, 一个是startup.bat, 它用于windows环境下启动tomcat; 另一个是startup.sh, 它用于linux环境下tomcat的启动. 两个文件中的逻辑是一样的, 我们只分析其中的startup.bat.

  • startup.bat的源码: startup.bat文件实际上就做了一件事情: 启动catalina.bat.
@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end
  • 当然如果你感兴趣,不妨也可以看下上面脚本的含义
    • .bat文件中@echo是打印指令, 用于控制台输出信息,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值