Tomcat starts batch processing -- catalina. bat, tomcatcatalina. bat

Source: Internet
Author: User

Tomcat starts batch processing -- catalina. bat, tomcatcatalina. bat

This batch processing is the core script for tomcat server startup and shutdown. Including .... (Various variables). This section describes the logic of this batch.
First look at the first part of the script:
**************************************** **************************************** ************
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"
Set RETVAL = % ERRORLEVEL %
Del/Q "% TEMP % \ % ~ Nx0.Y "> NUL 2> & 1
Exit/B % RETVAL %
: MainEntry
Del/Q "% TEMP % \ % ~ Nx0.run "> NUL 2> & 1
**************************************** **************************************** ************
The first line determines that if % 1 means that the first parameter is equal to run, it will jump directly to mainEntry. Two double quotation marks are used to prevent the parameter from carrying spaces; in the second row, if the TEMP environment variable is null, the system will jump to mainEntry. In the third row, the system will determine whether catalina exists in the TEMP environment variable directory. bat. the run file jumps directly to mainEntry. The fourth line inputs the letter Y into catalina. bat. run file; the fifth line determines if catalina does not exist. bat. the run file jumps to mainEntry. The sixth line will contain the letter Y, which is entered into catalina. bat. in the Y file; the seventh line is catalina. bat. Y is used as the input to execute the current batch processing. % * indicates all parameters. Row 8 assigns the % ERRORLEVEL % variable after execution to RETVAL. If the execution process encounters a problem, the value is non-zero; row 9 deletes catalina. bat. Y file, and the execution result is not output. In addition, STDERR is redirected to STDOUT. Row 10 exits the current batch processing script. And use the RETVAL variable as the return value. The remaining two lines of script are not described in detail.
The second part of the script mainly sets CATALINA_HOME and CATALINA_BASE variables.
**************************************** **************************************** ************
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 %"
Cd "% CURRENT_DIR %"
: GotHome
If exist "% CATALINA_HOME % \ bin \ catalina. bat" goto okHome
Goto end
: OkHome
If not "% CATALINA_BASE %" = "" goto gotBase
Set "CATALINA_BASE = % CATALINA_HOME %"
: GotBase
**************************************** **************************************** ************
Set the CATALINA_HOME environment variable. The logic is the same as that of startup. bat. Why do we need to set the CATALINA_HOME environment variable? To put it simply, you can run catalina. bat directly instead of using startup. bat. Set the CATALINA_BASE environment variable. Here, the value of CATALINA_HOME is directly assigned to it.
The third part of the script is to set the CLASSPATH environment variables and add various jar packages to the CLASSPATH.
**************************************** **************************************** ************
Set CLASSPATH =
If not exist "% CATALINA_BASE % \ bin \ setenv. bat" goto checkSetenvHome
Call "% CATALINA_BASE % \ bin \ setenv. bat"
Goto setenvDone
: CheckSetenvHome
If exist "% CATALINA_HOME % \ bin \ setenv. bat" call "% CATALINA_HOME % \ bin \ setenv. bat"
: SetenvDone
If exist "% CATALINA_HOME % \ bin \ setclasspath. bat" goto okSetclasspath
Goto end
: OkSetclasspath
Call "% CATALINA_HOME % \ bin \ setclasspath. bat" % 1
If errorlevel 1 goto end
If "% CLASSPATH %" = "" goto emptyClasspath
Set "CLASSPATH = % CLASSPATH % ;"
: EmptyClasspath
Set "CLASSPATH = % CLASSPATH % CATALINA_HOME % \ bin \ bootstrap. jar"
If not "% CATALINA_TMPDIR %" = "" goto gotTmpdir
Set "CATALINA_TMPDIR = % CATALINA_BASE % \ temp"
: GotTmpdir
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
**************************************** **************************************** ************
Set CLASSPATH to null to check whether setenv exists in the % CATALINA_BASE % \ bin directory. bat. If yes, call this batch of files. Otherwise, check whether setenv exists in the % CATALINA_HOME % \ bin directory. bat. Execute the command if it exists. Continue to determine whether % CATALINA_HOME % \ bin \ setclasspath exists. bat file. If it does not exist, it will jump to the end, indicating the setclasspath. bat is a necessary batch processing script and then runs setclasspath. bat script. % 1 indicates the parameter. If errorlevel 1 goto end indicates to execute this command. if the error value is greater than or equal to 1, it will jump directly to the end. if there is no error, continue to the next step and check whether the environment variable % CLASSPATH % is null, if it is not null, set CLASSPATH to % CLASSPATH % with a semicolon. Then, set % CATALINA_HOME % \ bin \ bootstrap. jar is added to classpath. This package is the tomcat kernel. Then set the temporary directory temp, append the tomcat-juli.jar package to classpath, the basic logic is to first find from the % CATALINA_BASE % \ bin directory, if it does not exist, then go to the % CATALINA_HOME % \ bin directory to find. Tomcat-juli.jar this package mainly contains tomcat System Log processing class, please review the third part of the fourth section-log framework for details.
The fourth part is the log configuration settings.
**************************************** **************************************** ************
If not "% LOGGING_CONFIG %" = "" goto 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
Set LOGGING_MANAGER =-Djava. util. logging. manager = org. apache. juli. ClassLoaderLogManager
: NoJuliManager
Set JAVA_OPTS = % JAVA_OPTS % LOGGING_MANAGER %
**************************************** **************************************** ************
The log implementation in Tomcat uses the log tool class that comes with jdk. The main two attributes can be configured, namely java. util. logging. config. file and java. util. logging. manager: first, determine whether the environment variable has LOGGING_CONFIG and use it directly if it exists. Otherwise, set LOGGING_CONFIG to-Dnop and determine whether % CATALINA_BASE % \ conf \ logging exists. properties. If yes, LOGGING_CONFIG is set to-Djava. util. logging. config. file = "% CATALINA_BASE % \ conf \ logging. properties ". Note: set JAVA_OPTS = % JAVA_OPTS % LOGGING_CONFIG %. You will find that there is no JAVA_OPTS variable or JAVA_OPTS environment variable in front of the original version, the purpose of this operation is to append all parameters to JAVA_OPTS. For example, if the O & M personnel already have the JAVA_OPTS variable, it will be appended to JAVA_OPTS after execution, if no JAVA_OPTS variable exists, it is used as a null value and does not affect the operation. The setting of the LOGGING_MANAGER variable is the same as that of LOGGING_CONFIG.
The fifth part is the initialization of some parameters before the command is executed.
**************************************** **************************************** ************
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
**************************************** **************************************** ************
Assign % _ RUNJAVA % variable to _ EXECJAVA, and % _ RUNJAVA % variable to setclasspath. the bat script has been set to % JRE_HOME % \ bin \ java, set MAINCLASS to tomcat's startup class Bootstrap, ACTION to start, and other variables are not initialized first. If the first parameter is jpda, set the JPDA variable as the value jpda. jpda is the Java platform debugging architecture, which provides convenient remote debugging; if the JPDA_TRANSPORT variable is null, it is set to dt_socket; if the JPDA_ADDRESS variable is null, it is set to 8000; if the JPDA_SUSPEND variable is null, it is set to n; if the JPDA_OPTS variable is null, set it to-agentlib: jdwp = transport = % JPDA_TRANSPORT %, address = % JPDA_ADDRESS %, server = y, suspend = % JPDA_SUSPEND %. Finally, a shift is used to move the parameter one by one. This section mainly initializes the JPDA startup command item and loads the JDWP proxy to the JVM of the application.
The sixth part of the command is to jump to different locations to execute different commands based on different parameters. In fact, it is also to assemble some parameters to prepare for the next step.
**************************************** **************************************** ************
If "% 1" "=" "debug" "goto doDebug
If "% 1" "=" "run" "goto doRun
If "% 1" "=" "start" "goto doStart
If "% 1" "=" "stop" "goto doStop
If "% 1" "=" "configtest" "goto doConfigTest
If "% 1" "=" "version" "goto doVersion
: DoDebug
Shift
Set _ EXECJAVA = % _ RUNJDB %
Set DEBUG_OPTS =-sourcepath "% CATALINA_HOME % \... \ java"
If not "" % 1 "" = ""-security "" goto execCmd
Shift
Set "SECURITY_POLICY_FILE = % CATALINA_BASE % \ conf \ catalina. policy"
Goto execCmd
: DoRun
Shift
If not "" % 1 "" = ""-security "" goto execCmd
Shift
Set "SECURITY_POLICY_FILE = % CATALINA_BASE % \ conf \ catalina. policy"
Goto execCmd
: DoStart
Shift
If not "% OS %" = "Windows_NT" goto noTitle
If "% TITLE %" = "" set TITLE = Tomcat
Set _ EXECJAVA = start "% TITLE %" % _ RUNJAVA %
Goto gotTitle
: NoTitle
Set _ EXECJAVA = start % _ RUNJAVA %
: GotTitle
If not "" % 1 "" = ""-security "" goto execCmd
Shift
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
**************************************** **************************************** ************
Previously, shift was used to move the parameter one by one. At this time, the parameter represented by % 1 is already the next parameter, perform different operations according to debug, run, start, stop, configtest, and version to the doDebug, doRun, doStart, doStop, doConfigTest, and doVersion labels. The following six operations are analyzed:
The logic of doDebug is to move the parameter one by one and set the _ EXECJAVA variable to % _ RUNJDB %, the _ RUNJDB variable has been set to % JAVA_HOME % \ bin \ jdb in the setclasspath batch processing script, set the DEBUG_OPTS variable, and then determine whether the parameter is equal to-security, that is, whether to start the security manager, if not, directly jump to the execCmd position. Otherwise, the parameter is moved one byte and the SECURITY_POLICY_FILE variable is set to % CATALINA_BASE % \ conf \ catalina. policy, This catalina. for more information about the role of policy, see Section 4 security framework. Finally, jump to the execCmd position.
The logic of doRun is to move the parameter one byte to determine whether the security manager is used. If the security manager is not used, it will jump directly to the execCmd position. Otherwise, the parameter will be moved one byte and the SECURITY_POLICY_FILE variable will be set, finally, jump to the execCmd position.
The logic of doStart is to move the parameter one by one. The TITLE of the command window is set according to whether the system is windows _ nt, and the TITLE variable is set as a Tomcat string. Set the _ EXECJAVA variable. If there is a title, add it to the startup command, then determine whether to use the security manager, move the parameter one by one, set SECURITY_POLICY_FILE, and finally jump to the execCmd position.
The logic of doStop and doConfigTest is similar. You can move the parameters one by one, set the ACTION variable to stop and configtest, clear the CATALINA_OPTS variable, and jump to the execCmd position.
DoVersion is actually to display the server information. You can directly call the java.exe program under the % JRE_HOME % \ bin directory, % CATALINA_HOME % \ lib \ catalina. jar as classpath, org. apache. catalina. util. serverInfo is used as the startup class to output server-related information and end the command.
Part 7: command execution.
**************************************** **************************************** ************
: ExecCmd
Set pai_line_args =
: SetArgs
If "% 1" "=" goto doneSetArgs
Set CMD_LINE_ARGS = % CMD_LINE_ARGS % 1
Shift
Goto setArgs
: DoneSetArgs
If not "% JPDA %" = "" goto doJpda
If not "% SECURITY_POLICY_FILE %" = "" goto doSecurity
% _ 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 %
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
**************************************** **************************************** ************
The first step is to collect the parameters, which have been seen before and will not be described here. The next step is to execute different commands Based on the parameter values, and use a diagram to describe the logic in it more clearly. 3-2-1-2. It mainly uses the JPDA and SECURITY_POLICY_FILE variables to determine whether to use the Java platform to debug the architecture and security manager. In this way, four different commands can be formed. Let's look at the details of the most comprehensive commands:
 
Figure 3-2-1-2
If you use both the security manager and the Java platform debugging system to start the service, the system will jump to the doSecurityJpda location.
% _ EXECJAVA %: start "Tomcat" "D: \ java \ jdk \ bin \ java" (assuming the java installation path is D: \ java \ jdk ).
% JAVA_OPTS %:-Djava. util. logging. config. file = "D: \ java \ apache-tomcat-7.0.39 \ conf \ logging. properties "-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager.
% CATALINA_OPTS %: null.
% JPDA_OPTS %:-agentlib: jdwp = transport = dt_socket, address = 8000, server = y, suspend = n.
% DEBUG_OPTS %: null.
% JAVA_ENDORSED_DIRS %: "D: \ apache-tomcat \ endorsed" (assume that the tomcat installation directory is D: \ apache-tomcat ).
% CLASSPATH % is: "D: \ apache-tomcat \ bin \ bootstrap. jar; D: \ apache-tomcat \ bin \ tomcat-juli.jar ".
% SECURITY_POLICY_FILE % is: D: \ apache-tomcat \ conf \ catalina. policy.
% CATALINA_BASE % is: D: \ apache-tomcat.
% CATALINA_HOME % is: D: \ apache-tomcat.
% CATALINA_TMPDIR % is: D: \ apache-tomcat \ temp.
% MAINCLASS % is org. apache. catalina. startup. Bootstrap.
% CMD_LINE_ARGS %: null.
% ACTION % is: start.
Assemble the preceding variable values into a command line that is the final STARTUP script.
Run catalinabat rull and startupbat In the tomcat command line. Are there any differences between them?

Startup. bat is the startup option of tomcat.
Catalina. bat is a configuration item of tomcat, which can be used to set the virtual memory size and growth of tomcat.

Tomcat cannot be started. The catalinabat file cannot be found.

This indicates that tomcat has started one and you need to disable it. Your port is occupied by port 8080.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.