startup.bat文件的主要作用就是找到catali.bat文件,並且執行它。
@echo off
rem -----------------------------------------------------------------------------------------------------------------------
/*
dos在運行批處理時,會依次執行批處理中的每條命令,並且會顯示在顯示器上,如果你不想讓他們顯示,可以加一個echo off。當然echo off本身也是一條命令,如果本條命令也不願意顯示,可以在echo off前面加@
*/
rem -----------------------------------------------------------------------------------------------------------------------
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 -----------------------------------------------------------------------------------------------------------------------
if "%OS%" == "Windows_NT" setlocal
/*
判斷當前系統是否為windows
*/
rem -----------------------------------------------------------------------------------------------------------------------
set "CURRENT_DIR=%cd%"
/*
設置當前目錄
*/
rem -----------------------------------------------------------------------------------------------------------------------
if not "%CATALINA_HOME%" == "" goto gotHome
/*
如果設置了CATALINA_HOME環境變量,就知道跳到下面的gotHome處執行
*/
set "CATALINA_HOME=%CURRENT_DIR%"
/*
如果沒有設置CATALINA_HOME環境變量,則設置環境變量為當前目錄
*/
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
/*
判斷一下catalina.bat是否找到了,如果找到了,直接跳到oKHome
*/
cd ..
/*
這里系統假設你開始已經進入了tomcat的bin目錄,所以就退到上一級目錄
*/
set "CATALINA_HOME=%cd%"
/*
現在再次設置CATALINA_HOME為tomcat的安裝目錄
*/
cd "%CURRENT_DIR%"
/*
進入dos的當前目錄
*/
: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
/*
如果還是找不到catalina.bat,則給出報錯提示
*/
:okHome
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_16/*如果本機已經啟動了其他tomcat,則可以通過設置java_home來運行第二個tomcat*/
set "EXECUTABLE=%CATALINA_HOME%\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
: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%執行catalina.bat文件,將
:end
