tomcat catalina.bat解读

1 篇文章 0 订阅

原文地址:http://supportopensource.iteye.com/blog/1884919

rem catalina.bat是tomcat所有脚本中最重要的脚本,完成几乎所有的tomcat操作。如启动,关闭等

@echo off
echo Enter the catalina.bat file ......
if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start/Stop Script for the CATALINA Server
rem
rem Environment Variable Prerequisites
rem
rem   Do not set the variables in this script. Instead put them into a script
rem   setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
rem
rem   CATALINA_HOME   May point at your Catalina "build" directory.
rem
rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
rem                   of a Catalina installation.  If not present, resolves to
rem                   the same directory that CATALINA_HOME points to.
rem
rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
rem                   "run" or "debug" command is executed.
rem                   Include here and not in JAVA_OPTS all options, that should
rem                   only be used by Tomcat itself, not by the stop process,
rem                   the version command etc.
rem                   Examples are heap size, GC logging, JMX ports etc.
rem
rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
rem                   the JVM should use (java.io.tmpdir).  Defaults to
rem                   %CATALINA_BASE%\temp.
rem
rem   JAVA_HOME       Must point at your Java Development Kit installation.
rem                   Required to run the with the "debug" argument.
rem
rem   JRE_HOME        Must point at your Java Runtime installation.
rem                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
rem                   are both set, JRE_HOME is used.
rem
rem   JAVA_OPTS       (Optional) Java runtime options used when any command
rem                   is executed.
rem                   Include here and not in CATALINA_OPTS all options, that
rem                   should be used by Tomcat and also by the stop process,
rem                   the version command etc.
rem                   Most options should go into CATALINA_OPTS.
rem
rem   JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
rem                   containing some jars in order to allow replacement of APIs
rem                   created outside of the JCP (i.e. DOM and SAX from W3C).
rem                   It can also be used to update the XML parser implementation.
rem                   Defaults to $CATALINA_HOME/endorsed.
rem
rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
rem                   command is executed. The default is "dt_socket".
rem
rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. The default is 8000.
rem
rem   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. Specifies whether JVM should suspend
rem                   execution immediately after startup. Default is "n".
rem
rem   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
rem                   and JPDA_SUSPEND are ignored. Thus, all required jpda
rem                   options MUST be specified. The default is:
rem
rem                   -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
rem                       address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
rem
rem   LOGGING_CONFIG  (Optional) Override Tomcat's logging config file
rem                   Example (all one line)
rem                   set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
rem
rem   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
rem                   Example (all one line)
rem                   set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
rem
rem   TITLE           (Optional) Specify the title of Tomcat window. The default
rem                   TITLE is Tomcat if it's not specified.
rem                   Example (all one line)
rem                   set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
rem
rem
rem
rem $Id: catalina.bat 1344732 2012-05-31 14:08:02Z kkolinko $
rem ---------------------------------------------------------------------------


rem Suppress Terminate batch job on CTRL+C
if not ""%1"" == ""run"" goto mainEntry
if "%TEMP%" == "" goto mainEntry
if exist "%TEMP%\%~nx0.run" goto mainEntry
echo Y>"%TEMP%\%~nx0.run"
if not exist "%TEMP%\%~nx0.run" goto mainEntry
echo Y>"%TEMP%\%~nx0.Y"
call "%~f0" %* <"%TEMP%\%~nx0.Y"
rem Use provided errorlevel
set RETVAL=%ERRORLEVEL%
del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1
exit /B %RETVAL%
:mainEntry
del /Q "%TEMP%\%~nx0.run" >NUL 2>&1


rem Guess CATALINA_HOME if not defined              rem 猜测CATALINA_HOME是否没有定义
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"                            rem 重新设置CATALINA_HOME环境变量为E:\code\web\tomcat
cd "%CURRENT_DIR%"


:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome    rem 如果在%CATALINA_HOME%\bin中存在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


:okHome
rem Copy CATALINA_BASE from CATALINA_HOME if not defined
if not "%CATALINA_BASE%" == "" goto gotBase         rem 如果设置了环境变量CATALINA_BASE,就直接跳到gotBase
set "CATALINA_BASE=%CATALINA_HOME%"                 rem 如果没有,将CATALINA_BASE设置为CATALINA_HOME


:gotBase
rem Ensure that any user defined CLASSPATH variables are not used on startup,
rem but allow them to be specified in setenv.bat, in rare case when it is needed.
set CLASSPATH=


rem Get standard environment variables
if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
call "%CATALINA_BASE%\bin\setenv.bat"           rem 如果在%CATALINA_BASE%\bin中存在setenv.bat,就调用setenv.bat脚本
goto setenvDone


:checkSetenvHome
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"   rem 如果在%CATALINA_HOME%\bin中存在setenv.bat,就调用setenv.bat脚本


:setenvDone
rem Get standard Java environment variables
if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
echo This file is needed to run this program
goto end


:okSetclasspath
call "%CATALINA_HOME%\bin\setclasspath.bat" %1  rem 如果在%CATALINA_HOME%\bin中存在setclasspath.bat,调用setclasspath.bat脚本并加上参数
if errorlevel 1 goto end                        rem 如果存在错误就退出


rem Add on extra jar file to CLASSPATH
rem Note that there are no quotes as we do not want to introduce random
rem quotes into the CLASSPATH
if "%CLASSPATH%" == "" goto emptyClasspath
set "CLASSPATH=%CLASSPATH%;"
:emptyClasspath
set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"


if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir        rem 如果配置了环境变量CATALINA_TMPDIR,则跳到gotTmpdir
set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
:gotTmpdir


rem Add tomcat-juli.jar to classpath
rem tomcat-juli.jar can be over-ridden per instance
if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"
goto juliClasspathDone
:juliClasspathHome
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
:juliClasspathDone


if not "%LOGGING_CONFIG%" == "" goto noJuliConfig     rem 如果配置了环境变量LOGGING_CONFIG,则跳到noJuliConfig
set LOGGING_CONFIG=-Dnop
if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
:noJuliConfig
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%


if not "%LOGGING_MANAGER%" == "" goto noJuliManager   rem 如果配置了环境变量LOGGING_MANAGER,则跳到noJuliManager
set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
:noJuliManager
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%


rem ----- Execute The Requested Command ---------------------------------------


echo Using CATALINA_BASE:   "%CATALINA_BASE%"
echo Using CATALINA_HOME:   "%CATALINA_HOME%"
echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
if ""%1"" == ""debug"" goto use_jdk               rem 如果变量%1里存在debug ,转到use_jdk位置
echo Using JRE_HOME:        "%JRE_HOME%"
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME:       "%JAVA_HOME%"
:java_dir_displayed
echo Using CLASSPATH:       "%CLASSPATH%"


set _EXECJAVA=%_RUNJAVA%                               rem setclasspath.bat中最后部分:set _RUNJAVA="%JRE_HOME%\bin\java"
set MAINCLASS=org.apache.catalina.startup.Bootstrap    rem 设置主启动类
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=


if not ""%1"" == ""jpda"" goto noJpda  rem 如果%1不是Jpda,则直接跳到noJpda
set JPDA=jpda                          rem 否则设置设置JPDA环境变量为jpda
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport  rem 如果设置了环境变量JPDA_TRANSPORT,就直接跳到gotJpdaTransport
set JPDA_TRANSPORT=dt_socket                           rem 否则设置JPDA_TRANSPORT为dt_socket
:gotJpdaTransport
if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=8000
:gotJpdaAddress
if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
set JPDA_SUSPEND=n
:gotJpdaSuspend
if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
:gotJpdaOpts
shift
:noJpda


if ""%1"" == ""debug"" goto doDebug                    rem 如果%1为debug,转到doDebug,运行debug模式
if ""%1"" == ""run"" goto doRun                        rem 如果%1为run,转到doRun,运行正常模式
if ""%1"" == ""start"" goto doStart                    rem 如果%1为start,转到doStart,启动tomcat
if ""%1"" == ""stop"" goto doStop                      rem 如果%1为stop,转到doStop,关闭tocmat
if ""%1"" == ""configtest"" goto doConfigTest          rem 
if ""%1"" == ""version"" goto doVersion                rem 如果%1为version,转到doVersion,显示tomcat的版本号


echo Usage:  catalina ( commands ... )                 rem 如果%1没有上述内容,输出下面几行,并结束
echo commands:
echo   debug             Start Catalina in a debugger
echo   debug -security   Debug Catalina with a security manager
echo   jpda start        Start Catalina under JPDA debugger
echo   run               Start Catalina in the current window
echo   run -security     Start in the current window with security manager
echo   start             Start Catalina in a separate window
echo   start -security   Start in a separate window with security manager
echo   stop              Stop Catalina
echo   configtest        Run a basic syntax check on server.xml
echo   version           What version of tomcat are you running?
goto end


:doDebug
rem shift /n 会将第n个参数(%n)去掉,后面的参数则向前移一位.不带参数与shift /1相同,去掉第一个
shift                                                     rem 将%2里的值转到%1
set _EXECJAVA=%_RUNJDB%                                   rem 将变量 _EXECJAVA设为_RUNJDB变量的值
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"   rem 设定DEBUG_OPTS变量
if not ""%1"" == ""-security"" goto execCmd               rem 如果%1不为-security,转到execCmd位置
shift                                                     rem 将%2里的值转到%1
echo Using Security Manager                               rem 输出该行
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"   rem 设定SECURITY_POLICY_FILE变量的值
goto execCmd                                              rem 转到execCmd位置


:doRun
shift                                                     rem 将%2里的值(-security)转到%1(%1:start)
if not ""%1"" == ""-security"" goto execCmd               rem 如果%1不为-security,转到execCmd位置
shift                                                     rem 将%2里的值转到%1
echo Using Security Manager                               rem  输出该行
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"   rem 设定SECURITY_POLICY_FILE变量的值
goto execCmd                                              rem 转到execCmd位置


:doStart
shift                                                     rem 将%2里的值转到%1
if not "%OS%" == "Windows_NT" goto noTitle                rem 如果OS变量不为Windows_NT,转到noTitle
if "%TITLE%" == "" set TITLE=Tomcat                       rem 如果TITLE为空,设置TITLE为Tomcat,即设置TITLE (标题)参数为“Tomcat” 
set _EXECJAVA=start "%TITLE%" %_RUNJAVA%                  rem 设定_EXECJAVA变量的值,start表示在新的窗口(标题为Tomcat)执行命令
rem set _EXECJAVA=%_RUNJAVA%                              rem 去掉start "%TITLE%",表示在当前窗口中执行命令
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%
:gotTitle
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
goto execCmd


:doStop
shift
set ACTION=stop
set CATALINA_OPTS=
goto execCmd


:doConfigTest
shift
set ACTION=configtest
set CATALINA_OPTS=
goto execCmd


:doVersion
%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
goto end




:execCmd
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
rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda                                 rem 如果JPDA变量不为空,转到doJpda位置
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity             rem 如果SECURITY_POLICY_FILE变量不为空,转到doSecurity位置
rem 如果都没有,则执行下面命令
rem echo显示要执行的命令
echo %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%


rem start "Tomcat" "E:\code\web\tomcat\..\jdk\bin\java"  
rem -Djava.util.logging.config.file="E:\code\web\tomcat\conf\logging.properties"  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
rem -Djava.endorsed.dirs="E:\code\web\tomcat\endorsed" 
rem -classpath "E:\code\web\tomcat\bin\bootstrap.jar;E:\code\web\tomcat\bin\tomcat-juli.jar" 
rem -Dcatalina.base="E:\code\web\tomcat" -Dcatalina.home="E:\code\web\tomcat" -Djava.io.tmpdir="E:\code\web\tomcat\temp" 
rem org.apache.catalina.startup.Bootstrap  start




goto end


:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end


:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end


:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end


:end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值