@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
上面代码的相关含义:express
setlocal
- - - -将后面的环境变量设置为临时环境变量(直到endlocal 命令的出现)apache
rem Guess CATALINA_HOME if not defined
set “CURRENT_DIR=%cd%”
- - - - 将 CURRENT_DIR 环境变量设置为当前路径
if not “%CATALINA_HOME%” == “” goto gotHome
- - - - 判断是否存在 CATALINA_HOME 环境变量。若是存在该环境变量跳转到gotHome标签
set “CATALINA_HOME=%CURRENT_DIR%”
- - - - 若是不存在CATALINA_HOME环境变量将CATALINA_HOME 设置为CURRENT_DIR所指向的路径(即当前路径)
if exist “%CATALINA_HOME%\bin\catalina.bat” goto okHome
- - - - 判断是否存在%CATALINA_HOME%\bin\catalina.bat文件,若是存在跳转到okHome标签
cd ..
- - - -这里是假设你开始已经进入到了tomcat的bin目录,因此就退到上一级目录(变为了当前目录)
set “CATALINA_HOME=%cd%”
- - - - 将CATALINA_HOME 设置为当前路径
cd “%CURRENT_DIR%”
- - - - 进入上面设置的 CURRENT_DIR 路径(这里又变成了当前路径)
:gotHome
if exist “%CATALINA_HOME%\bin\catalina.bat” goto okHome
- - - -判断是否存在%CATALINA_HOME%\bin\catalina.bat该文件tomcat
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
若是不存在打印上面的内容,而且跳转到end标签,结束程序
:okHome服务器
set “EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat”
- - - - 将 EXECUTABLE环境变量设置为tomcat服务器bin目录下的catalina.bat路径
rem Check that target executable exists
if exist “%EXECUTABLE%” goto okExec
- - - - 判断是否存在catalina.bat文件,若是存在跳转到okExec标签。
echo Cannot find “%EXECUTABLE%”
echo This file is needed to run this program
goto end
- - - - 若是没有找到catalina.bat文件打印上面内容,并跳转到end标签。app
:okExecless
rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
将 CMD_LINE_ARGS 设置为空(CMD_LINE_ARGS为设置参数的一个环境变量)。
:setArgs
if “”%1”“==”“”” goto doneSetArgs
检查%1是否为空,若是为空就表示没有参数了,设置参数结束,转至doneSetArgs标签
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
- - - - 若是不为空就把%1指向的参数追加到CMD_LINE_ARGS这个环境变量中。
shift
- - - - 删除第一个参数,后面的参数左移一个位置。
goto setArgs
- - - -跳转到 setArgs 标签。
:doneSetArgsui
call “%EXECUTABLE%” start %CMD_LINE_ARGS%
- - - 经过call命令调用catalina.bat启动脚本,并传递参数
:endthis
从代码咱们能够看出 执行startup.bat至关于执行catalina.bat startcode
在tomcat的bin目录下还存在着configtest.bat文件、shutdown.bat文件、version.bat文件,他们的实质都是调用的catalina.bat文件,只不过是他们传递的参数不相同罢了。orm
运行configtest.bat文件,至关于执行catalina.bat configtest;
运行configtest.bat文件,至关于执行catalina.bat stop;
运行version.bat文件,至关于执行catalina.bat version;
可是运行digest.bat文件时,他执行的文件是tool-wrapper.bat文件传递的参数是
-server org.apache.catalina.realm.RealmBase。
能够看出catalina.bat文件才是tomcat的关键!!