@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的關鍵!!