【web服务器】——Tomcat start.bat文件详解

            通常情况下,我们配置好了配置文件后,就开始启动start.bat批处理文件,进行tomcat的启动。


        那么tomcat是如何一步步启动的呢?我们接下来就来详细介绍一下,tomcat的启动过程。


        通过阅读start.bat批处理文件,我们不难发现,它其实就是检查catalina.bat 执行所需环境,并调用catalina.bat 批处理文件。接下来我们详细解释一下start.bat文件的内容。


        start.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%"              //设置CURRENT_DIR变量为(当前工作目录)D:\01-计算机\win8\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\bin
if not "%CATALINA_HOME%" == "" goto gotHome    //判断CATALINA_HOME变量是否配置,如果配置了则跳转到 goHome命令
set "CATALINA_HOME=%CURRENT_DIR%"              //如果没有设置则设置CATALINA_HOME为当前目录,变量值为:D:\01-计算机\win8\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\bin

if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome      //如果当前工作目录存在catalina.bat文件,则跳转到okHome命令
cd ..         //回到上级目录 D:\01-计算机\win8\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36
set "CATALINA_HOME=%cd%"   //更改CATALINA_HOME变量值为:D:\01-计算机\win8\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36
cd "%CURRENT_DIR%"      //切换当前工作目录

:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome    //如果当前工作目录存在catalina.bat文件,则跳转到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"    //    设置EXECUTABLE(执行文件)变量

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec           //如果存在EXECUTABLE变量,则执行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=            //清除CMD_LINE_ARGS环境变量原来的值  

:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1          //给 CMD_LINE_ARGS 添加参数,并以空格隔开
shift
goto setArgs

:doneSetArgs
call "%EXECUTABLE%" start %CMD_LINE_ARGS%     //打开新窗口,执行 EXECUTABLE 环境变量所代表的catalina.bat 批处理文件与 CMD_LINE_ARGS 代表的参数  


:end                               //结束


      总结:         


   通过观察发现,start.bat和shutdown.bat文件的区别就是执行参数不同,在start.bat中是:call "%EXECUTABLE%" start %CMD_LINE_ARGS%,而在shutdown.bat中是stop。而真正的启动和关闭tomcat的过程是在catalina.bat中执行的。只让我想到了我们的函数封装,以及多态的特点。相同的执行过程,只因为传递的参数不同,而得到不同的结果。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幸运的梦之星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值