启动tomcat是启动tomcat安装目录下bin文件夹中的startup.bat文件,在cmd中运行如下:
然后会弹出一个新的窗口继续运行,如果没有报错在浏览器中输入localhost:8080就会出现tomcat欢迎界面
下面是start.bat的代码:
if "%OS%" == "Windows_NT" setlocal //如果本机OS是windows_NT 则设置本机环境变量
set "CURRENT_DIR=%cd%" //设置CURRENT_DIR 变量(当前工作目录)D:\eclipse\apache-tomcat-6.0.32\bin
if not "%CATALINA_HOME%" == "" goto gotHome //如果配置了 CATALINA_HOME 环境变量跳转执行 gotHome
set "CATALINA_HOME=%CURRENT_DIR%" //如果没有设置,则设置 CATALINA_HOME 变量为:D:\eclipse\apache-tomcat-6.0.32\bin
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome //D:\eclipse\apache-tomcat-6.0.32\bin\bin)下是否存在
cd .. //回到上级子目录D:\eclipse\apache-tomcat-6.0.32
set "CATALINA_HOME=%cd%" // 更改 CATALINA_HOME 变量值为:D:\eclipse\apache-tomcat-6.0.32
cd "%CURRENT_DIR%" //回到D:\eclipse\apache-tomcat-6.0.32\bin
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome //D:\eclipse\apache-tomcat-6.0.32\bin 下是否存在
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" //设置EXECUTABLE
if exist "%EXECUTABLE%" goto okExec //EXECUTABLE是否存在
echo Cannot find "%EXECUTABLE%" //不存在直接返回报错
echo This file is needed to run this program
goto end
:okExec
set CMD_LINE_ARGS= //清除CMD_LINE_ARGS环境变量原来的值
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1 //给 CMD_LINE_ARGS 添加参数,并以空格隔开
shift
goto setArgs //截掉第一个参数,使第二个参数变为第一个参数
:doneSetArgs
call "%EXECUTABLE%" start %CMD_LINE_ARGS% 打开新窗口,执行 EXECUTABLE 环境变量所代表的catalina.bat 批处理文件
:end
由此可见startup.bat只是找catalina.bat,并调用catalina.bat执行文件