startup.bat文件的主要做用就是找到catali.bat文件,而且執行它。java
@echo offexpress
rem -----------------------------------------------------------------------------------------------------------------------apache
/*windows
dos在運行批處理時,會依次執行批處理中的每條命令,而且會顯示在顯示器上,若是你不想讓他們顯示,能夠加一個echo off。固然echo off自己也是一條命令,若是本條命令也不肯意顯示,能夠在echo off前面加@數組
*/tomcat
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.app
/*less
rem爲註釋ui
*/this
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