以下爲catalina.bat的原文(tomcat7.0.85),逐句解釋,請各位按自己的理解程度自行跳段。【此符號內爲解釋內容】
@echo off【關閉回顯,DOS批處理,非DOS命令行,表示在此語句後所有運行的命令都不顯示命令行本身,加@表示自身也不顯示】
rem Licensed to the Apache Software Foundation (ASF) under one or more【rem:相當於註釋】
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.
【翻譯:根據一個或多個貢獻者許可協議許可給Apache Software Foundation(ASF)。
有關版權所有權的其他信息,請參閱隨此工作分發的NOTICE文件.ASF根據Apache許可證2.0版(“許可證”)將此文件許可給您;
除非符合許可,否則您不得使用此文件。您可以在以下位置獲取許可證副本 http://www.apache.org/licenses/LICENSE-2.0
除非適用法律要求或書面同意,根據許可證分發的軟件按“原樣”分發,不附帶任何明示或暗示的保證或條件。
有關管理許可下的權限和限制的特定語言,請參閱許可證。】
rem ---------------------------------------------------------------------------
rem Start/Stop Script for the CATALINA Server【catalina服務的開啓/暫停腳本】
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.
【不要在此腳本中設置變量。 而是將它們放入CATALINA_BASE / bin中的腳本setenv.bat中,以使您的自定義分開。】
rem
rem WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:【當你在WINDOWS服務運行TOMCAT時:】
rem Note that the environment variables that affect the behavior of this
rem script will have no effect at all on Windows Services. As such, any
rem local customizations made in a CATALINA_BASE/bin/setenv.bat script
rem will also have no effect on Tomcat when launched as a Windows Service.
rem The configuration that controls Windows Services is stored in the Windows
rem Registry, and is most conveniently maintained using the "tomcatXw.exe"
rem maintenance utility, where "X" is the major version of Tomcat you are
rem running.
【翻譯:請注意,影響此腳本行爲的環境變量在Windows服務上根本不起作用。
因此,在作爲Windows服務啓動時,在CATALINA_BASE / bin / setenv.bat腳本中進行的任何本地自定義也不會對Tomcat產生任何影響。
控制Windows服務的配置存儲在Windows註冊表中,使用“tomcatXw.exe”維護實用程序最方便地進行維護,其中“X”是您運行的Tomcat的主要版本。】
rem
rem CATALINA_HOME May point at your Catalina "build" directory.【可以指向您的Catalina“構建”目錄。】
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.
【(可選)用於解析Catalina安裝的動態部分的基本目錄。
如果不存在,則解析爲CATALINA_HOME指向的同一目錄。】
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.
【(可選)執行“start”,“run”或“debug”命令時使用的Java運行時選項。
包含在這裏,而不是JAVA_OPTS中的所有選項,只能由Tomcat本身使用,而不是由停止進程,版本命令等使用。
例如堆大小,GC日誌記錄,JMX端口等。】
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.
【(可選)JVM應使用的臨時目錄的目錄路徑位置(java.io.tmpdir)。 默認爲%CATALINA_BASE%\ temp。】
rem
rem JAVA_HOME Must point at your Java Development Kit installation.
rem Required to run the with the "debug" argument.【必須指向Java Development Kit安裝。 需要使用“debug”參數運行。】
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.
【必須指向Java Runtime安裝。 如果爲空,則默認爲JAVA_HOME。
如果同時設置了JRE_HOME和JAVA_HOME,則使用JRE_HOME。】
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.
【(可選)執行任何命令時使用的Java運行時選項。
包括此處而不是CATALINA_OPTS中的所有選項,Tomcat應該使用它們,也可以使用停止進程,版本命令等。
大多數選項應該進入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 Note that Java 9 no longer supports this feature.
rem Defaults to $CATALINA_HOME/endorsed.
【(可選)包含一些jar的分號分隔目錄列表,以便替換在JCP外部創建的API(即來自W3C的DOM和SAX)。
它還可用於更新XML解析器實現。 請注意,Java 9不再支持此功能。 默認爲$ CATALINA_HOME / endorsed。】
rem
rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
rem command is executed. The default is "dt_socket".
【(可選)執行“jpda start”命令時使用的JPDA傳輸。 默認值爲“dt_socket”。】
rem
rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
rem command is executed. The default is 8000.
【(可選)執行“jpda start”命令時使用的Java運行時選項。 默認值爲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".
【(可選)執行“jpda start”命令時使用的Java運行時選項。 指定JVM是否應在啓動後立即暫停執行。 默認值爲“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:
【(可選)執行“jpda start”命令時使用的Java運行時選項。
如果使用,則忽略JPDA_TRANSPORT,JPDA_ADDRESS和JPDA_SUSPEND。
因此,必須指定所有必需的jpda選項。 默認爲:】
rem
rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
rem
rem JSSE_OPTS (Optional) Java runtime options used to control the TLS
rem implementation when JSSE is used. Default is:
rem "-Djdk.tls.ephemeralDHKeySize=2048"
【(可選)用於在使用JSSE時控制TLS實現的Java運行時選項。 默認值爲:“ - Djdk.tls.ephemeralDHKeySize = 2048”】
rem
rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file
rem Example (all one line)
【(可選)覆蓋Tomcat的日誌配置文件示例(所有寫在一行)】
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)
【(可選)覆蓋Tomcat的日誌管理器示例(所有寫在一行)】
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)
【(可選)指定Tomcat窗口的標題。 如果未指定,則默認TITLE爲Tomcat。 示例(所有寫在一行)】
rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
rem ---------------------------------------------------------------------------
setlocal【在執行 SETLOCAL 之後所做的環境改動只限於批處理文件。沒寫endlocal也會在批處理結束時隱含endlocal的被執行】
rem Suppress Terminate batch job on CTRL+C【禁止用CTRL+C終止批處理作業】
if not ""%1"" == ""run"" goto mainEntry【"%1" 表示第一個參數,goto str 表示跳轉到:str處,str指代任何字符】
if "%TEMP%" == "" goto mainEntry【如果temp變量爲空(也就是沒設置),就跳轉到mainEntry】
if exist "%TEMP%\%~nx0.run" goto mainEntry【%0表示文件名,~刪除引號,猜測這一段表示%temp%地址下的.run文件】
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【刪掉%temp%地址下的.run文件(猜測)】
rem Guess CATALINA_HOME if not defined【CATALINA_HOME沒有被聲明的情況,猜測一下】
set "CURRENT_DIR=%cd%"【設置變量CURRENT_DIR爲當前目錄】
if not "%CATALINA_HOME%" == "" goto gotHome【如果CATALINA_HOME環境變量沒有,去gotHome】
set "CATALINA_HOME=%CURRENT_DIR%"【設置CATALINA_HOME爲CURRENT_DIR】
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome【如果CATALINA_HOME下是tomcat主目錄,去okHome】
cd ..【返回上級目錄】
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome【再次確認,如果在這個目錄下能找到這個bat,就去okhome】
echo The CATALINA_HOME environment variable is not defined correctly【告訴用戶未正確定義CATALINA_HOME環境變量】
echo This environment variable is needed to run this program【運行此程序需要此環境變量】
goto end【跳轉到end】
:okHome
rem Copy CATALINA_BASE from CATALINA_HOME if not defined【如果未定義,則從CATALINA_HOME複製一個給CATALINA_BASE】
if not "%CATALINA_BASE%" == "" goto gotBase
set "CATALINA_BASE=%CATALINA_HOME%"
:gotBase
rem Ensure that any user defined CLASSPATH variables are not used on startup,【確保在啓動時不使用任何用戶定義的CLASSPATH變量】
rem but allow them to be specified in setenv.bat, in rare case when it is needed.【但允許在setenv.bat中指定它們,在極少數情況下需要時。】
set CLASSPATH=
rem Get standard environment variables【獲取標準環境變量】
if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome【如果CATALINA_BASE環境下setenv.bat不存在,去checkSetenvHome】
call "%CATALINA_BASE%\bin\setenv.bat"【調用setenv.bat程序(該文件爲設置環境變量)】
goto setenvDone
:checkSetenvHome
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"【如果CATALINA_HOME的地址下存在setenv.bat,那就調用】
:setenvDone
rem Get standard Java environment variables【獲取標準Java環境變量】
if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath【存在setclasspath.bat ,就去okSetclasspath,否則執行下面的】
echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"【沒有找到"%CATALINA_HOME%\bin\setclasspath.bat"】
echo This file is needed to run this program【這個文件是程序運行必備的】
goto end【跳轉到end】
:okSetclasspath
call "%CATALINA_HOME%\bin\setclasspath.bat" %1【調用這個bat的第一個參數】
if errorlevel 1 goto end【errorlevel等於1表示失敗】
rem Add on extra jar file to CLASSPATH【將額外的jar文件添加到CLASSPATH】
rem Note that there are no quotes as we do not want to introduce random【請注意,沒有引號,因爲我們不想隨機引入】
rem quotes into the CLASSPATH【引用CLASSPATH】
if "%CLASSPATH%" == "" goto emptyClasspath【CLASSPATH爲空,去emptyClasspath,否則執行下方】
set "CLASSPATH=%CLASSPATH%;"【設置Classpath】
:emptyClasspath
set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"【沒設定的話就讀取CATALINA_HOME下路徑給CLASSPATH】
if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir【判斷有沒有配臨時文件夾的環境變量,配了就直接走下一步】
set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"【沒配就在這設置一下】
:gotTmpdir
rem Add tomcat-juli.jar to classpath【將tomcat-juli.jar添加到classpath】
rem tomcat-juli.jar can be over-ridden per instance【每個實例都可以覆蓋tomcat-juli.jar】
if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome【如果這個路徑下tomcat-juli.jar不存在就重設置一下】
set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"【好像存不存在都設置了一樣的路徑】
goto juliClasspathDone【去下一項】
:juliClasspathHome
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
:juliClasspathDone
if not "%JSSE_OPTS%" == "" goto gotJsseOpts【環境變量JSSE_OPTS不爲空的情況下去gotJsseOpts,這個參數應該是設置JVM相關運行參數的變量】
set JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"【這裏設置瞬時Diffie-Hellman公共密鑰】
:gotJsseOpts
set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"【設置JAVA_OPTS環境變量的值】
if not "%LOGGING_CONFIG%" == "" goto noJuliConfig【配置了LOGGING_CONFIG的話,去noJuliConfig】
set LOGGING_CONFIG=-Dnop【如果未使用JULI,則將LOGGING_CONFIG設置爲無害標誌。-D是安全的】
if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig【如果這個路徑下找不到的話】
set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
:noJuliConfig
if not "%LOGGING_MANAGER%" == "" goto noJuliManager
set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager【設置logging-manager】
:noJuliManager
rem Java 9 no longer supports the java.endorsed.dirs【Java 9不再支持java.endorsed.dirs系統屬性】
rem system property. Only try to use it if
rem JAVA_ENDORSED_DIRS was explicitly set
rem or CATALINA_HOME/endorsed exists.【只有在顯式設置JAVA_ENDORSED_DIRS或存在CATALINA_HOME/endorsed時才嘗試使用它。】
set ENDORSED_PROP=ignore.endorsed.dirs【查到的資料不足,不知道這是幹啥的】
if "%JAVA_ENDORSED_DIRS%" == "" goto noEndorsedVar
set ENDORSED_PROP=java.endorsed.dirs
goto doneEndorsed
:noEndorsedVar
if not exist "%CATALINA_HOME%\endorsed" goto doneEndorsed
set ENDORSED_PROP=java.endorsed.dirs
:doneEndorsed
rem Configure JAVA 9 specific start-up parameters【配置JAVA 9特定的啓動參數】
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.lang=ALL-UNNAMED"
set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
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【第一個參數爲debug】
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%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA= 【設置一堆不知道是啥的參數】
if not ""%1"" == ""jpda"" goto noJpda
set JPDA=jpda
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
set 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【debug】
if ""%1"" == ""run"" goto doRun【run】
if ""%1"" == ""start"" goto doStart【start】
if ""%1"" == ""stop"" goto doStop【stop】
if ""%1"" == ""configtest"" goto doConfigTest【configtest】
if ""%1"" == ""version"" goto doVersion【version】
echo Usage: catalina ( commands ... )
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
shift【更改批處理文件中可替換參數的位置】
set _EXECJAVA=%_RUNJDB%
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
goto execCmd
:doRun
shift
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
goto execCmd
:doStart
shift
if "%TITLE%" == "" set TITLE=Tomcat
set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
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
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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
:doSecurity
%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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