startup.bat

Posted open-technology

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了startup.bat相关的知识,希望对你有一定的参考价值。

一、阅读说明

1 术语说明

1.1 下述内容使用“服务器”均代表Tomcat 7.0.75Web服务器。

1.2 下述内容使用%SERVER_PATH%表示服务器根目录

二、startup.bat文件源码

1 startup.bat文件位置

startup.bat文件位置:%SERVER_PATH%\bin\startup.bat

2 源码内容

(以下内容经处理,去除不必要的信息)

 1 @echo off
 2 
 3 rem ---------------------------------------------------------------------------
 4 rem Start script for the CATALINA Server
 5 rem ---------------------------------------------------------------------------
 6 
 7 setlocal
 8 
 9 rem Guess CATALINA_HOME if not defined
10 set "CURRENT_DIR=%cd%"
11 if not "%CATALINA_HOME%" == "" goto gotHome
12 set "CATALINA_HOME=%CURRENT_DIR%"
13 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
14 cd ..
15 set "CATALINA_HOME=%cd%"
16 cd "%CURRENT_DIR%"
17 :gotHome
18 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
19 echo The CATALINA_HOME environment variable is not defined correctly
20 echo This environment variable is needed to run this program
21 goto end
22 :okHome
23 
24 set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"
25 
26 rem Check that target executable exists
27 if exist "%EXECUTABLE%" goto okExec
28 echo Cannot find "%EXECUTABLE%"
29 echo This file is needed to run this program
30 goto end
31 :okExec
32 
33 rem Get remaining unshifted command line arguments and save them in the
34 set CMD_LINE_ARGS=
35 :setArgs
36 if ""%1""=="""" goto doneSetArgs
37 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
38 shift
39 goto setArgs
40 :doneSetArgs
41 
42 call "%EXECUTABLE%" start %CMD_LINE_ARGS%
43 
44 :end

三、源码分析 

 1 @echo off
 2 setlocal
 3 set "CURRENT_DIR=%cd%"
 4 rem 将当前文件位置赋值给CURRENT_DIR变量
 5 if not "%CATALINA_HOME%" == "" goto gotHome
 6 rem 如果变量CATALINA_HOME不为空,跳转至gotHome
 7 
 8 set "CATALINA_HOME=%CURRENT_DIR%"
 9 rem 如果变量CATALINA_HOME不存在,将当前文件目录赋值给CATALINA_HOME
10 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
11 rem 如果存在%CATALINA_HOME%\bin\catalina.bat文件,跳转至okHome
12 cd ..
13 rem 返回目录上一级
14 set "CATALINA_HOME=%cd%"
15 rem 设置变量CATALINA_HOME为当前目录
16 cd "%CURRENT_DIR%"
17 rem 返回文件所在目录
18 :gotHome
19 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
20 rem 如果存在%CATALINA_HOME%\bin\catalina.bat,则跳转至okHome
21 echo The CATALINA_HOME environment variable is not defined correctly
22 echo This environment variable is needed to run this program
23 goto end
24 :okHome
25 
26 set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"
27 rem 设置变量EXECUTABLE为%CATALINA_HOME%\bin\catalina.bat
28 rem Check that target executable exists
29 if exist "%EXECUTABLE%" goto okExec
30 rem 如果存在文件%EXECUTABLE%,则跳转至okExec
31 echo Cannot find "%EXECUTABLE%"
32 echo This file is needed to run this program
33 goto end
34 :okExec
35 
36 rem Get remaining unshifted command line arguments and save them in the
37 set CMD_LINE_ARGS=
38 :setArgs
39 if ""%1""=="""" goto doneSetArgs
40 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
41 shift
42 rem 将参数向左移位
43 goto setArgs
44 :doneSetArgs
45 
46 call "%EXECUTABLE%" start %CMD_LINE_ARGS%
47 rem 调用%CATALINA_HOME%\bin\catalina.bat文件并传递参数
48 
49 :end

四、结论

服务器startup.bat主要做了以下几件事情:

1、检查环境

2、准备参数

3、调用catalina.bat

以上是关于startup.bat的主要内容,如果未能解决你的问题,请参考以下文章