From tomcat boot to SPRINGIOC container initialization

Source: Internet
Author: User

Tomcat is typically started from startup.bat/startup.sh, then starts Catalina.bat/catalina.bat, and then starts the Catalina.jar package

So what did they do when they started?

The bottom starts with startup.bat (//TODO startup.sh pause) To see what happens during startup.

1@echo off2 rem Licensed to the Apache software Foundation (ASF) under one or more3 REM Contributor license agreements. See the NOTICE file distributed with4REM This work foradditional information regarding copyright ownership.5REM The ASF licenses this file to under the Apache License, Version 2.06REM (The"License"); You are not a use this file exceptinchCompliance with7 REM the License. Obtain a copy of the License at8 REM9REM http://www.apache.org/licenses/LICENSE-2.0Ten REM OneREM unless required by applicable or agreed toinchwriting, Software AREM distributed under the License is distributed in an" as is"BASIS, - REM without warranties or CONDITIONS of any KIND, either express or implied. -REM See the License forThe specific language governing permissions and the REM Limitations under the License. -  - if "%os%"=="Windows_NT"setlocal -REM--------------------------------------------------------------------------- +rem Start Script forThe CATALINA Server -REM--------------------------------------------------------------------------- +  AREM Guess Catalina_homeifNot defined atSet"current_dir=%cd%" - ifNot"%catalina_home%"==""Goto Gothome -Set"catalina_home=%current_dir%" - ifExist"%catalina_home%\bin\catalina.bat"Goto Okhome - CD.. -Set"catalina_home=%cd%" inCd"%current_dir%" - : Gothome to ifExist"%catalina_home%\bin\catalina.bat"Goto Okhome + echo the CATALINA_HOME environment variable is not defined correctly - echo This environment variable are needed to run theGotoEnd * : Okhome $ Panax NotoginsengSet"Executable=%catalina_home%\bin\catalina.bat" -  the REM Check that target executable exists + ifExist"%executable%"Goto okexec AEcho Cannot find"%executable%" the echo This file was needed to run +GotoEnd - : Okexec $  $REM Get remaining unshifted command line arguments and save theminch the -Set cmd_line_args= - : Setargs the if ""%""==""""Goto Donesetargs -Set cmd_line_args=%cmd_line_args%%1Wuyi Shift the Goto Setargs - :d Onesetargs Wu  -  AboutPager"%executable%"Start%cmd_line_args% $  -:End
View Code

line1 @echo off @ Turn this command back on, the echo off command is to turn off batch operations performed by the output

Line17 if "%os%" = = "Windows_NT" setlocal if there is an OS this environment variable and the value is WINDOWS_NT, start setting the local environment variable. Where the setlocal command is interpreted as: starts localization of environment variables in a batch file. Localization continues until a matching endlocal command is encountered or the end of the batch file is reached. The localized environment variables are started in the batch file, and these variables are valid until the end of the endlocal command or bat file that corresponds to it (setlocal). Just now found that another version of Tomcat (7.0.67) on the computer has canceled the evaluation of OS variables and setlocal directly.

line23-35 Guess catalina_home If not defined, find catalina_home this variable and determine if Catalina.bat exists.

REM Guess Catalina_homeifNot Definedset"current_dir=%cd%"ifNot"%catalina_home%"==""Goto Gothomeset"catalina_home=%current_dir%"ifExist"%catalina_home%\bin\catalina.bat"Goto OKHOMECD. Set"catalina_home=%cd%"CD"%current_dir%": GothomeifExist"%catalina_home%\bin\catalina.bat"Goto Okhomeecho The catalina_home environment variable is not defined Correctlyecho This environment variable is nee Ded to run this programgotoEnd: Okhome

Line23 set "current_dir=%cd%" Current_dir is the first temporary environment variable after launch, the value of this environment variable is%cd%, "%cd%" gets the current directory of BAT file execution, cd = Current_dir abbreviation, c : \tool\apache-tomcat-7.0.67\bin.

Line24 if not "%catalina_home%" = "" goto gothome if the catalina_home environment variable is set, goto gothome node, but I estimate development few have set this environment variable (anyway I never); Variable words continue.

The Line25 set "catalina_home=%current_dir%" setting catalina_home (considered another temporary environment variable) executes the directory for the current BAT file, which is C:\tool\apache-tomcat-7.0.67\ Bin

Line exist "%catalina_home%\bin\catalina.bat" goto okhome if Catalina.bat exists under%catalina_home%e\bin\, goto The Okhome node. The default installed Tomcat Catalina.bat and Startup.bat are under%catalina_home%e\bin\.

Line27 CD. If there is no Catalina.bat file in%catalina_home%e\bin\, go back to the parent directory that is C:\tool\apache-tomcat-7.0.67.

Line28 set "catalina_home=%cd%" and then change the catalina_home=c:\tool\apache-tomcat-7.0.67.

Line29 CD "%current_dir%" Back to C:\tool\apache-tomcat-7.0.67\bin.

Line31 if exist "%catalina_home%\bin\catalina.bat" goto okhome again to determine if catalina.bat exists if a goto okhome node exists , there is no output to execute line32-33, and then goto end node, this batch finishes.

Line37 Set "Executable=%catalina_home%\bin\catalina.bat" Setting executable node

Line39-44 again determines whether the%catalina_home%\bin\catalina.bat exists, if there is a goto okexec node, and there is no goto end node, the batch ends.

line46-53 setting Cmd_line_args

Set cmd_line_args=: Setargsif""%1"" = =" " "" Goto Donesetargsset Cmd_ Line_args=%cmd_line_args%%1shiftgoto setargs:donesetargs

LINE47-48: Assigns the returned result under the Setargs node to the Cmd_line_args variable.

line49-52 If%1 is the first parameter is empty, goto Donesetargs, otherwise loop all parameters, add a space after all the parameters are stitched together, assigned to the Cmd_line_args variable, all parameters are processed after the execution line56

The shift command    in a batch file can refer to a parameter of%0~%9,%0 that is the batch file itself, or an external command:%1~%9 is a batch parameter, also called a formal parameter: if the actual parameter of the replacement parameter exceeds the value specified in the batch file (9) And you want to apply these arguments to the batch file, the shift command can help you implement it! It changes the position of the replaceable parameter in the batch file,and the value of shift [/n] n is [0,8] and is an integer; [/n] is an optional parameter, when n is given a value, it means that the command starts from the nth parameter, and when n gives a value of 0, 1 or shift without any of the command options, indicates that the replacement parameter in the batch file is shifted left one position, followed by replacement parameters being filled up until the replaceable parameter is empty.
shift Command

Line56 call "%executable%" start%cmd_line_args% calls the executable parameter to start and top stitching Cmd_line_args (possibly empty).

At this point, Startup.bat ends, it can be seen that the main purpose is to find and start Catalina.bat.

  

From tomcat boot to SPRINGIOC container initialization

Related Article

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.