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%incatalina.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%incatalina.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 FilesJavajdk1.5.0_16/*如果本机已经启动了其他tomcat,则可以通过设置java_home来运行第二个tomcat*/
set "EXECUTABLE=%CATALINA_HOME%incatalina.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