Tomcat Startup

0

Startup process

In this post we will cover the basic flow that follows up when we click on startup.bat.
We touch some important concepts which we will delve into in the coming posts. There is also a broader internal structure of tomcat that the digester creates as it reads through server.xml.

Difference between catalina home and catalina base? 

CATALINA_HOME identifies the location of the Tomcat binaries, whereas CATALINA_BASE sets the root location of a given running Tomcat instance.


The reason for keeping these separate is to allow multiple Tomcat instances to be started (with independent configurations), while relying on a single set of binaries.

Class loaders

Classes internal to tomcat

Loads classes from CATALINA_HOME/lib. These classes should be visible to tomcat internal code and all web applications.
Loads classes from folder path defined in catalina.properties. These classes should be visible only to the tomcat internal code.

Class loader repositories

Tomcat Startup



Tomcat Startup




Web applications

Loads classes from WEB-INF/classes and WEB-INF/lib. These classes are visible only to the owning web application.
Loads classes from folder path defined in catalina.properties. These classes should be visible to all web applications hosted by the tomcat.

When a web application needs any other class, instead of delegating to its parent, this custom class loader will first check within the WEB-INFclasses and WEB-INFlib folders. Only if it is not found there will it delegate to its parent class loader, which will then follow the standard delegating pattern.

Common class loader path

This is already overridden in catalina.properties:
common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar

Server class loader

We can override the property in catalina.properties.
server.loader=

Shared class loader

We can override the property in catalina.properties.
shared.loader=

Class loader hierarchy


Tomcat Startup
Tomcat Startup

Startup.bat

When we run startup.bat. It tries to set CATALINA_HOME and CATALINA_BASE. Once done it calls catalina.bat to do the actual start of tomcat. Catalina.bat confirms that it has a valid CATALINA_HOME and CATALINA_BASE properties. It then resets the classpath to point to bootstrap.jar. If tomcat-juli.jar exists (logger related stuff), catalina.bat appends it to classpath.
Final classpath would look like CLASSPATH=C:tc7.0.xoutputbuildbinbootstrap.jar;C:tc7.0.xoutputbuildbintomcat-juli.jar
In the next set of commands, catalina.bat would construct the java execution command. The final command would look something like below:

start “Tomcat” “C:Program FilesJavajdk1.7.0_11binjava” -Djava.util.logging.config.file=”C:tc7.0.xoutputbuildconflogging.properties” -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=”C:tc7.0.xoutputbuildendorsed” -classpath “C:tc7.0.xoutputbuildbinbootstrap.jar;C:tc7.0.xoutputbuildbintomcat-juli.jar” -Dcatalina.base=”C:tc7.0.xoutputbuild” -Dcatalina.home=”C:tc7.0.xoutputbuild” -Djava.io.tmpdir=”C:tc7.0.xoutputbuildtemp” org.apache.catalina.startup.Bootstrap start

I have pasted below the sequence of commands that run when we call startup.bat

startup.bat

C:\tc7.0.x\output\build\bin>if "Windows_NT" == "Windows_NT" setlocal

C:\tc7.0.x\output\build\bin>set "CURRENT_DIR=C:\tc7.0.x\output\build\bin" 

C:\tc7.0.x\output\build\bin>if not "" == "" goto gotHome 

C:\tc7.0.x\output\build\bin>set "CATALINA_HOME=C:\tc7.0.x\output\build\bin" 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\bin\catalina.bat" goto okHome 

C:\tc7.0.x\output\build\bin>cd .. 

C:\tc7.0.x\output\build>set "CATALINA_HOME=C:\tc7.0.x\output\build" 

C:\tc7.0.x\output\build>cd "C:\tc7.0.x\output\build\bin" 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\catalina.bat" goto okHome 

C:\tc7.0.x\output\build\bin>set "EXECUTABLE=C:\tc7.0.x\output\build\bin\catalina.bat" 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\catalina.bat" goto okExec 

C:\tc7.0.x\output\build\bin>set CMD_LINE_ARGS= 

C:\tc7.0.x\output\build\bin>if """" == """" goto doneSetArgs 

C:\tc7.0.x\output\build\bin>call "C:\tc7.0.x\output\build\bin\catalina.bat" start  


catalina.bat
=============

C:\tc7.0.x\output\build\bin>if "Windows_NT" == "Windows_NT" setlocal

C:\tc7.0.x\output\build\bin>if not ""start"" == ""run"" goto mainEntry 

C:\tc7.0.x\output\build\bin>del /Q "C:\Users\mokkara\AppData\Local\Temp\catalina.bat.run"  1>NUL 2>&1 

C:\tc7.0.x\output\build\bin>set "CURRENT_DIR=C:\tc7.0.x\output\build\bin" 

C:\tc7.0.x\output\build\bin>if not "C:\tc7.0.x\output\build" == "" goto gotHome 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\catalina.bat" goto okHome 

C:\tc7.0.x\output\build\bin>if not "" == "" goto gotBase 

C:\tc7.0.x\output\build\bin>set "CATALINA_BASE=C:\tc7.0.x\output\build" 

C:\tc7.0.x\output\build\bin>set CLASSPATH= 

C:\tc7.0.x\output\build\bin>if not exist "C:\tc7.0.x\output\build\bin\setenv.bat" goto checkSetenvHome 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\setenv.bat" call "C:\tc7.0.x\output\build\bin\setenv.bat" 

C:\tc7.0.x\output\build\bin>if exist "C:\tc7.0.x\output\build\bin\setclasspath.bat" goto okSetclasspath 

C:\tc7.0.x\output\build\bin>call "C:\tc7.0.x\output\build\bin\setclasspath.bat" start 


setClasspath.bat
==================

C:\tc7.0.x\output\build\bin>if ""start"" == ""debug"" goto needJavaHome 

C:\tc7.0.x\output\build\bin>if not "" == "" goto gotJreHome 

C:\tc7.0.x\output\build\bin>if not "C:\Program Files\Java\jdk1.7.0_11" == "" goto gotJavaHome 

C:\tc7.0.x\output\build\bin>set "JRE_HOME=C:\Program Files\Java\jdk1.7.0_11" 

C:\tc7.0.x\output\build\bin>if not exist "C:\Program Files\Java\jdk1.7.0_11\bin\java.exe" goto noJreHome 

C:\tc7.0.x\output\build\bin>if not exist "C:\Program Files\Java\jdk1.7.0_11\bin\javaw.exe" goto noJreHome 

C:\tc7.0.x\output\build\bin>goto okJava 

C:\tc7.0.x\output\build\bin>if not "" == "" goto gotEndorseddir 

C:\tc7.0.x\output\build\bin>set "JAVA_ENDORSED_DIRS=C:\tc7.0.x\output\build\endorsed" 

C:\tc7.0.x\output\build\bin>set _RUNJAVA="C:\Program Files\Java\jdk1.7.0_11\bin\java" 

C:\tc7.0.x\output\build\bin>set _RUNJDB="C:\Program Files\Java\jdk1.7.0_11\bin\jdb" 

C:\tc7.0.x\output\build\bin>goto end 


back to catalina.bat
======================

C:\tc7.0.x\output\build\bin>exit /b 0 

C:\tc7.0.x\output\build\bin>if errorlevel 1 goto end 

C:\tc7.0.x\output\build\bin>if "" == "" goto emptyClasspath 

C:\tc7.0.x\output\build\bin>set "CLASSPATH=C:\tc7.0.x\output\build\bin\bootstrap.jar" 

C:\tc7.0.x\output\build\bin>if not "" == "" goto gotTmpdir 

C:\tc7.0.x\output\build\bin>set "CATALINA_TMPDIR=C:\tc7.0.x\output\build\temp" 

C:\tc7.0.x\output\build\bin>if not exist "C:\tc7.0.x\output\build\bin\tomcat-juli.jar" goto juliClasspathHome 

C:\tc7.0.x\output\build\bin>set "CLASSPATH=C:\tc7.0.x\output\build\bin\bootstrap.jar;C:\tc7.0.x\output\build\bin\tomcat-juli.jar" 

C:\tc7.0.x\output\build\bin>goto juliClasspathDone 

C:\tc7.0.x\output\build\bin>if not "" == "" goto noJuliConfig 

C:\tc7.0.x\output\build\bin>set LOGGING_CONFIG=-Dnop 

C:\tc7.0.x\output\build\bin>if not exist "C:\tc7.0.x\output\build\conf\logging.properties" goto noJuliConfig 

C:\tc7.0.x\output\build\bin>set LOGGING_CONFIG=-Djava.util.logging.config.file="C:\tc7.0.x\output\build\conf\logging.properties" 

C:\tc7.0.x\output\build\bin>set JAVA_OPTS= -Djava.util.logging.config.file="C:\tc7.0.x\output\build\conf\logging.properties" 

C:\tc7.0.x\output\build\bin>if not "" == "" goto noJuliManager 

C:\tc7.0.x\output\build\bin>set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 

C:\tc7.0.x\output\build\bin>set JAVA_OPTS= -Djava.util.logging.config.file="C:\tc7.0.x\output\build\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 

C:\tc7.0.x\output\build\bin>echo Using CATALINA_BASE:   "C:\tc7.0.x\output\build" 

C:\tc7.0.x\output\build\bin>echo Using CATALINA_HOME:   "C:\tc7.0.x\output\build" 

C:\tc7.0.x\output\build\bin>echo Using CATALINA_TMPDIR: "C:\tc7.0.x\output\build\temp" 

C:\tc7.0.x\output\build\bin>if ""start"" == ""debug"" goto use_jdk 

C:\tc7.0.x\output\build\bin>echo Using JRE_HOME:        "C:\Program Files\Java\jdk1.7.0_11" 

C:\tc7.0.x\output\build\bin>goto java_dir_displayed 

C:\tc7.0.x\output\build\bin>echo Using CLASSPATH:       "C:\tc7.0.x\output\build\bin\bootstrap.jar;C:\tc7.0.x\output\build\bin\tomcat-juli.jar" 

C:\tc7.0.x\output\build\bin>set _EXECJAVA="C:\Program Files\Java\jdk1.7.0_11\bin\java" 

C:\tc7.0.x\output\build\bin>set MAINCLASS=org.apache.catalina.startup.Bootstrap 

C:\tc7.0.x\output\build\bin>set ACTION=start 

C:\tc7.0.x\output\build\bin>set SECURITY_POLICY_FILE= 

C:\tc7.0.x\output\build\bin>set DEBUG_OPTS= 

C:\tc7.0.x\output\build\bin>set JPDA= 

C:\tc7.0.x\output\build\bin>if not ""start"" == ""jpda"" goto noJpda 

C:\tc7.0.x\output\build\bin>if ""start"" == ""debug"" goto doDebug 

C:\tc7.0.x\output\build\bin>if ""start"" == ""run"" goto doRun 

C:\tc7.0.x\output\build\bin>if ""start"" == ""start"" goto doStart 

C:\tc7.0.x\output\build\bin>shift

C:\tc7.0.x\output\build\bin>if not "Windows_NT" == "Windows_NT" goto noTitle 

C:\tc7.0.x\output\build\bin>if "" == "" set TITLE=Tomcat 

C:\tc7.0.x\output\build\bin>set _EXECJAVA=start "Tomcat" "C:\Program Files\Java\jdk1.7.0_11\bin\java" 

C:\tc7.0.x\output\build\bin>goto gotTitle 

C:\tc7.0.x\output\build\bin>if not """" == ""-security"" goto execCmd 

C:\tc7.0.x\output\build\bin>rem Get remaining unshifted command line arguments and save them in the 

C:\tc7.0.x\output\build\bin>set CMD_LINE_ARGS= 

C:\tc7.0.x\output\build\bin>if """" == """" goto doneSetArgs  

C:\tc7.0.x\output\build\bin>if not "" == "" goto doJpda 

C:\tc7.0.x\output\build\bin>if not "" == "" goto doSecurity 

C:\tc7.0.x\output\build\bin>start "Tomcat" "C:\Program Files\Java\jdk1.7.0_11\bin\java"  -Djava.util.logging.config.file="C:\tc7.0.x\output\build\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager   -Djava.endorsed.dirs="C:\tc7.0.x\output\build\endorsed" -classpath "C:\tc7.0.x\output\build\bin\bootstrap.jar;C:\tc7.0.x\output\build\bin\tomcat-juli.jar" -Dcatalina.base="C:\tc7.0.x\output\build" -Dcatalina.home="C:\tc7.0.x\output\build" -Djava.io.tmpdir="C:\tc7.0.x\output\build\temp" org.apache.catalina.startup.Bootstrap  start 

C:\tc7.0.x\output\build\bin>goto end 

Tomcat’s Internal structure

Tomcat Startup
Tomcat Startup
Share.

Leave A Reply