How Tomcat works reading notes 17 starting Tomcat under

Source: Internet
Author: User
Tags stop script

In the previous section, the starting position of our program is still bootstrap, and now we start the class with the bat file.
Before analyzing Catalina.bat, let's look at a few simple DOS commands we can use.
Fundamentals 1 REM Annotations, the interpreter does not perform the REM start command
2 Pause to pause a batch file that is executing, press any key to continue
3 echo Displays a piece of text in the console
If the value of the displayed variable needs to be added before and after the variable as echo%var% if the name of the operating system to be output is echo%os%
4 echo off can hide the command itself if you want to hide the echo off itself is @echo off
5 Set a variable
You can look at one of the following examples
@echo off
Echo, how are you?
Pause
Set a=15
Echo%a%
Echo, then press to exit.
Echo%os%
Pause

6 Label use: Identifies a label, and the Goto is used together
7 goto jumps to the appropriate label
Look at the following example
echo Start
Goto END
Echo, you can't see me.
: End
Echo Endss
Pause
After running the above command, the console will only appear
Start
Endss

8 If execution condition test
There are three ways to use
Test the value of a variable
Set var=15
If%var%=15 Echo is 15
Test whether the file exists
If exist c:/file.text echo exists file

9 Not take reverse
Set var=15
If not%var%=15 Echo is not 15

10 Receiving parameters
The first argument%2 with%1 represents the second and so on
If there is a ss.bat inside the following
Echo%1
In the console, call SS with the following command
SS Hello
It will output the first parameter Hello

One shift
To move the parameter back equals to copy%2 to%1;%3.%2

Call another command

SetLocal make changes to the variable to only the valid bat file in this bat file after the end of the variable restore the original value

Start opening a new window
Start name command
Name is the name of the new window followed by the command to be executed in a new window
Of course, there's no command.


There is a bin folder under the Tomcat installation directory
When the CD goes in, run Catalina on the command line to run the bat file.
However, some parameters are required when running


It's an exciting time to see the source.

We'll look at the code by calling Catalina start.

I use//to make comments

Catalina.bat
@echo Off//Hide command rem Licensed to the Apache software Foundation (ASF) under one or Morerem contributor license agreements. See the NOTICE file distributed Withrem This work for additional information regarding copyright Ownership.rem the ASF l Icenses this file to you under the Apache License, Version 2.0rem (the "License");  Except in compliance Withrem the License. Obtain a copy of the License Atremrem Http://www.apache.org/licenses/LICENSE-2.0remrem unless required by APPL Icable law or agreed to in writing, Softwarerem distributed under the License are distributed on a "as is" Basis,rem Witho  UT warranties or CONDITIONS of any KIND, either express or Implied.rem see the License for the specific language governing Permissions Andrem Limitations Under the license.//above is a note whether the OS is windows_nt setlocal above have if "%os%" = "Windows_NT" s Etlocalrem---------------------------------------------------------------------------rem start/stop Script for theCATALINA serverremrem Environment Variable Prerequisitesremrem do not set the variables in this script. Instead put them into a scriptrem setenv.bat in Catalina_base/bin to keep your customizations Separate.remrem CATALINA _home your Catalina "build" Directory.remrem catalina_base (Optional) BASE directory for resolving Dyna  Mic Portionsrem of a Catalina installation.   If not present, resolves Torem the same directory that catalina_home points To.remrem catalina_opts (Optional)                   Java runtime options used when the "start", rem "Run" or "Debug" command is Executed.rem Include here and not in the java_opts all options, which shouldrem only is used by Tomcat itself, not by th  E Stop process,rem The version command Etc.rem Examples is heap size, GC logging, JMX Ports Etc.remrem Catalina_tmpdir (Optional) Directory path location of temporary direCtoryrem the JVM should use (Java.io.tmpdir). Defaults Torem%catalina_base%\temp.remrem Java_home must point at your JAVA development Kit ins Tallation.rem Required to run the with the ' debug ' Argument.remrem jre_home must point at your Java Runtime Installation.rem Defaults to Java_home if empty. If Jre_home and Java_homerem are both set, Jre_home is Used.remrem java_opts (Optional) JAVA run Time options used when any Commandrem are Executed.rem Include here and not in CATALINA _opts all options, Thatrem should is used by Tomcat and also by the stop Process,rem t He version command Etc.rem Most options should go to Catalina_opts.remrem java_endorsed_dirs (Option AL) Lists of semi-colon separated directoriesrem containing some jars in order to allow replacement O F Apisrem created outside of the JCP (i.e. DOM and SAX from the website). REM It can also is use D to update the XML parser Implementation.rem Defaults to $CATALINA _home/endorsed.remrem Jpda_transpor T (Optional) JPDA transport used when the "JPDA start" rem command is executed.                   The default is ' Dt_socket '. Remrem jpda_address (Optional) Java runtime options used when the "JPDA start" rem command is executed.                   The default is 8000.remrem jpda_suspend (Optional) Java runtime options used when the "JPDA start" rem command is executed. Specifies whether JVM should suspendrem execution immediately after startup. Default is ' n '. Remrem jpda_opts (Optional) Java runtime options used when the "JPDA start" REM Co Mmand is executed. If used, Jpda_transport, Jpda_address,rem and Jpda_suspend are ignored.       Thus, all required Jpdarem            Options must be specified. The default Is:remrem-agentlib:jdwp=transport=%jpda_transport%,rem Address=%jpda_                   Address%,server=y,suspend=%jpda_suspend%remrem logging_config (Optional) Override Tomcat ' s LOGGING CONFIG Filerem Example (all one line) REM set logging_config= "-djava.util.logging.config.file=%catalina_bas E%\conf\logging.properties "Remrem Logging_manager (Optional) Override Tomcat ' s logging managerrem Exam PLE (all one line) REM set logging_manager= "-djava.util.logging.manager=org.apache.juli.classloaderlogman Ager "Remrem title (Optional) specify the title of the Tomcat window.                   The Defaultrem TITLE is Tomcat if it's not a specified.rem Example (All-line) REM Set title=tomcat.cluster#1.server#1 [%date%%time%]remremremrem $Id: Catalina.bat 1344732 2012-05-31 14:08: 02Z Kkolinko $rem---------------------------------------------------------------------------rem Suppress Terminate batch job on Ctrl+cif not ""%1 "" = = "Run" "goto mainentry//If the first parameter is not run go to Mainentry label 11 line after if"%temp% "=" "goto mainentryif Exist"%temp%\%~nx0.run "got o mainentryecho y> "%temp%\%~nx0.run" If not exist "%temp%\%~nx0.run" goto Mainentryecho y> "%temp%\%~nx0. Y "Call"%~f0 "%* <"%temp%\%~nx0. Y "REM Use provided Errorlevelset retval=%errorlevel%del/q"%temp%\%~nx0. Y ">nul 2>&1exit/b%retval%:mainentry//Don't understand del/q"%temp%\%~nx0.run ">nul 2>&1rem Guess C Atalina_home if not Definedset "current_dir=%cd%"//CD is the current path if not "%catalina_home%" = = "" Goto gothome//Not equal to empty go to G Othomeset "catalina_home=%current_dir%"//if equal to empty, think Catalina.bat folder is//catalina_       Homeif exist "%catalina_home%\bin\catalina.bat" goto OKHOMECD. Determine if the catalina_home is present bin\catalina.bat//If it does not exist return to the previous level of the directory//To remember normally catalina.bat would have been inBin directory Set "catalina_home=%cd%" CD "%current_dir%": gothome if Exist "%catalina_home%\bin\catalina.bat" goto okhome//To this It's all right. There is a bat file to Okhome//See echo the CATALINA_HOME environment variable is not defined Correctlyecho this environment var Iable is needed to run this Programgoto end:okhomerem Copy catalina_base from Catalina_home if not definedif "%catalin a_base% "= =" "Goto gotbase//English note it's clear. Set" catalina_base=%catalina_home% ": Gotbaserem ensure that any user defined CLASS PATH variables is isn't used on Startup,rem if allow them to be specified in SetEnv.bat, in rare case while it is needed.se T Classpath=rem Get Standard environment variables//is called Setenv.batif not exist "%catalina_base%\bin\setenv.bat" goto che Cksetenvhomecall "%catalina_base%\bin\setenv.bat" goto Setenvdone:checksetenvhomeif exist "%catalina_home%\bin\ SetEnv.bat "Call"%catalina_home%\bin\setenv.bat ": Setenvdonerem Get standard Java environment variables// Call Setclasspathif exist "%catalina_home%\bin\setClasspath.bat "Goto Oksetclasspathecho Cannot find"%catalina_home%\bin\setclasspath.bat "echo this file was needed to run T His programgoto end:oksetclasspathset basedir=%catalina_home%call "%catalina_home%\bin\setclasspath.bat"// Setclasspath.bat checks the environment variable java_home//and sets the following variable//set java_endorsed_dirs=%basedir%\common\endorsed//set CLASSPATH=% Java_home%\lib\tools.jar//set _runjava= "%java_home%\bin\java"//set _runjavaw= "%JAVA_HOME%\BIN\JAVAW"//set _RUNJDB = "%java_home%\bin\jdb"//set _runjavac= "%java_home%\bin\javac" rem Add on extra jar files to Classpathif "%jsse_home%" = = " "Goto Nojsse//Read English annotation set classpath=%classpath%;%jsse_home%\lib\jcert.jar;%jsse_home%\lib\jnet.jar;%jsse_home%\lib\ Jsse.jar:noJsseset Classpath=%classpath%;%catalina_home%\bin\bootstrap.jarif not "%catalina_base%" = = "goto Gotbaseset Catalina_base=%catalina_home%:gotbaseif not "%catalina_tmpdir%" = = "goto Gottmpdirset CATALINA_TMPDIR=% Catalina_base%\temp:gottmpdirrem-----Execute The requested Command---------------------------------------Echo using catalina_base: "%catalina_base%" Echo using Catalina_home: "%catalina_home%" Echo usin G Catalina_tmpdir: "%catalina_tmpdir%" If ""%1 "" = = "" Debug "" Goto Use_jdkecho Using jre_home: "%jre_home%" goto Java _dir_displayed:use_jdkecho using java_home: "%java_home%": Java_dir_displayedecho using CLASSPATH: "%classpath% "Set _execjava=%_runjava%set mainclass=org.apache.catalina.startup.bootstrapset action=startset SECURITY_POLICY_ File=set debug_opts=set jpda=if not ""%1 "" = = "" JPDA "" goto NOJPDA///The first parameter is start to see NOJPDA 15 rows after set Jpda=jpdaif not "%jpda_ transport% "= =" "Goto gotjpdatransportset jpda_transport=dt_socket:gotjpdatransportif not"%jpda_address% "= =" "Goto Go Tjpdaaddressset jpda_address=8000:gotjpdaaddressif not "%jpda_suspend%" = = "" Goto gotjpdasuspendset JPDA_SUSPEND=n: Gotjpdasuspendif not "%jpda_opts%" = = "goto Gotjpdaoptsset jpda_opts=-agentlib:jdwp=transport=%jpda_transport%, Address=%jpda_address%,server=y,suspend=%jpda_suspeNd%:gotjpdaoptsshift:nojpdaif "" "%1" "= =" "Debug" "Goto Dodebugif" "%1" "= =" "Run" "Goto dorunif" "%1" "= =" "Start" "Goto D Ostart//hehe If ""%1 "" = = "" Stop "" Goto dostopif ""%1 "" = = "" Configtest "" Goto doconfigtestif ""%1 "" = = "" Version "" Goto do Versionecho Usage:catalina (Commands ...)  echo Commands:echo Debug Start Catalina in a debuggerecho debug-security debug Catalina with a security Managerecho jpda start start Catalina under Jpda Debuggerecho run start Catalina in the current  Windowecho run-security start in the current window with security Managerecho start start Catalina in A separate Windowecho start-security start in a separate window with security Managerecho stop Stop C Atalinaecho configtest Run A basic syntax check on Server.xmlecho version what version of Tomcat is You running?goto end:dodebugshiftset _execjava=%_runjdb%set debug_opts=-sourcepath "%CATALINA_HOME%\..\.. \java "If not" "%1" "= =" "-security" "Goto execcmdshiftecho Using Security Managerset" Security_policy_file=%catalina_ Base%\conf\catalina.policy "goto execcmd:dorunshiftif not" "%1" "= =" "-security" "Goto Execcmdshiftecho Using Security  Managerset "Security_policy_file=%catalina_base%\conf\catalina.policy" goto execcmd:dostartshift//move parameter if not "%OS%" = = "Windows_NT" goto notitle//Just already said OS is windows_ntif "%title%" = "" Set Title=tomcatset _execjava=start "%title%"%_         runjava%//title is Tomcatgoto gottitle//_execjava This is the later command: Notitleset _execjava=start%_runjava%:gottitle We've moved the parameters before, but we do not have a second parameter to see ExecCmd after 24 rows if not ""%1 "" = = ""-security "" Goto execcmdshiftecho Using Security Manager Set "Security_policy_file=%catalina_base%\conf\catalina.policy" goto execcmd:dostopshiftset ACTION=stopset CATALINA _opts=goto execcmd:doconfigtestshiftset action=configtestset Catalina_opts=goto execCmd:doVersion%_EXECJAVA%- Classpath "%catalina_home%\lib\catalina.jar" org.aPache.catalina.util.ServerInfogoto end:execcmdrem Get remaining unshifted command line arguments and save them in Theset C Md_line_args=:setargs//The first parameter at this time is empty so go to see Donesetargsif ""%1 "" = = "" "Goto donesetargsset cmd_line_args=%cmd_line_args%% 1shiftgoto Setargs:donesetargsrem Execute Java with the applicable propertiesif not "%jpda%" = = "" Goto DOJPDA//Two variables are empty I F 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%//on my computer after assigning the above variables is//start" Tomcat "" C:\j2sdk1.4.2_02\bin\java "-//djava.endorsed.dirs=". \common\endorsed "-classpath//" C:\j2sdk1.4.2_02\lib\tools.jar; \bin\bootstrap.jar "-//dcatalina.base=": "-dcatalina,home=": "-djava.io.tmpdir=": \temp "//org.apache.catalina.startup.bootstrap start//explain//Start a new window called Tomcat and then call JAVA commands from-djava to/temp are parameters//Run is org.apache.catalina.startup.Bootstrap parameter is start//I'm tired of going to important finish//Thank you gltgoto end//To see 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:dojpdaif 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//To end in this


Actually, it's not the first class.
When to be when the ~ ~ ~
Startup.bat
@echo offif "%os%" = = "Windows_NT" Setlocalrem--------------------------------------------------------------------- ------REM Start script for the CATALINA serverremrem $Id: startup.bat,v 1.4 2002/01/15 02:55:38 Patrickl Exp $rem-------- -------------------------------------------------------------------rem Guess catalina_home if not definedif "%    Catalina_home% "= =" "Goto gothomeset catalina_home=.   A point is the current directory if exist "%catalina_home%\bin\catalina.bat" goto okhomeset catalina_home=: Two things superior directory AH today posture: gothome//on the first level of the directory is a bin folder, so go to okhomeif exist "%catalina_home%\bin\catalina.bat" Goto Okhomeecho The Catalina_home environment variable is isn't defined Correctlyecho this environment variable are needed to run this Programgot o end:okhomeset executable=%catalina_home%\bin\catalina.batrem Check that target executable existsif exist "%EXECUTABLE % "Goto okexec//executable definitely have yes go to see Okexececho cannot find%executable%echo This file was needed to run this programgoto en D:okexecrem Get RemaIning unshifted command line arguments and save them in Theset cmd_line_args=:setargsif ""%1 "" = = "" "Goto Donesetargs// There are no parameters so go to donesetargsset cmd_line_args=%cmd_line_args%%1shiftgoto setargs:donesetargscall "%EXECUTABLE%" Start%CMD_ line_args%//Call Bin\catalina.bat and the parameter is Start:end



Tomcat finally ended thanks GLT

How Tomcat works reading notes 17 starting Tomcat under

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.