Catalina.bat detailed

Source: Internet
Author: User
Tags apache tomcat

Catalina.bat is the most important script in all of Tomcat's scripts, completing almost all tomcat operations. such as start, close, and so on, are all done by the Catalina.bat script. Next, I'll analyze the Tomcat Catalina.bat script.

First of all, omit the catalina.bat opening many annotations, these annotations mainly explain what each variable is doing. If you need to, you can read English on your own. It's not translated here.

REM Guess Catalina_home if not defined see if the Tomcat directory is the same as in Startup.bat, not explained. If you need one, you can read my other blog post.
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
echo the CATALINA_HOME environment variable is not defined correctly
echo this environment variable are needed to run
Goto END
: Okhome

REM GET Standard Environment variables
If exist "%catalina_home%\bin\setenv.bat" call "%catalina_home%\bin\setenv.bat" if there is a SetEnv.bat script that calls it, my Tomcat does not have this script

REM GET standard Java environment variables
If exist "%catalina_home%\bin\setclasspath.bat" goto Oksetclasspath See if there is a Setclasspath.bat script, and if so, go to the Oksetclasspath location
echo cannot find%catalina_home%\bin\setclasspath.bat otherwise outputs the following two lines and exits
echo this file was needed to run
Goto END
: Oksetclasspath Oksetclasspath Location

Set basedir=%catalina_home% set BASEDIR variable is the same as Catalina_home variable value
Call "%catalina_home%\bin\setclasspath.bat"%1 calls the Setclasspath.bat script and adds parameters
if errorlevel 1 goto End If there is an error exiting

rem Add on extra jar files to CLASSPATH set jsse_home variable, if present join CLASSPATH, does not exist skip

If "%jsse_home%" = = "goto Nojsse Check for the existence of jsse_home variable
Set Classpath=%classpath%;%jsse_home%\lib\jcert.jar;%jsse_home%\lib\jnet.jar;%jsse_home%\lib\jsse.jar If there is a join to the CLASSPATH variable behind
: Nojsse
Set Classpath=%classpath%;%catalina_home%\bin\bootstrap.jar add Bootstrap.jar to CLASSPATH

If not "%catalina_base%" = = "goto gotbase If the catalina_base variable is not empty, skip, go to gotbase position
Set catalina_base=%catalina_home% if blank, Catalina_base is set to the value of the Catalina_home variable
: Gotbase

If not "%catalina_tmpdir%" = = "goto gottmpdir catalina_tmpdir not empty, skip, go to Gottmpdir location
Set Catalina_tmpdir=%catalina_base%\temp if empty, set Catalina_tmpdir to the value of the%catalina_base%\temp variable (that is, tomcat\temp)
: Gottmpdir

If not exist "%catalina_home%\bin\tomcat-juli.jar" goto nojuli If there is no Tomcat-juli.jar this class, go to Nojuli location
Set java_opts=%java_opts%-djava.util.logging.manager=org.apache.juli.classloaderlogmanager- djava.util.logging.config.file= "%catalina_base%\conf \logging.properties" if present, add the variable to the java_opts
: Nojuli


Set java_opts=%java_opts%-xms128m-xmx512m-dfile. ENCODING=UTF8-DUSER.TIMEZONE=GMT- Djava.security.auth.login.config=%catalina_home%/conf/jaas.config setting java_opts variable

echo Using catalina_base:%catalina_base% output catalina_base Variable value
echo Using catalina_home:%catalina_home% output catalina_home Variable value
echo Using catalina_tmpdir:%catalina_tmpdir% output Catalina_tmpdir Variable value
If ""%1 "" = = "" Debug "" Goto USE_JDK if there is debug in variable% 1, go to use_jdk position
echo Using jre_home:%jre_home% output jre_home Variable value
Goto java_dir_displayed Go to java_dir_displayed
: USE_JDK
echo Using java_home:%java_home% output java_home Variable value
: java_dir_displayed
The following lines set the corresponding variables
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_shmem
: Gotjpdatransport
If not "%jpda_address%" = = "goto gotjpdaaddress
Set Jpda_address=jdbconn
: gotjpdaaddress
If not "%jpda_suspend%" = = "goto gotjpdasuspend
Set Jpda_suspend=n
: Gotjpdasuspend
If not "%jpda_opts%" = = "goto gotjpdaopts
Set Jpda_opts=-xdebug-xrunjdwp:transport=%jpda_transport%,address=%jpda_address%,server=y,suspend=%jpda_suspend %
: gotjpdaopts
Shift
: NOJPDA

If ""%1 "" = = "" Debug "" Goto Dodebug if%1 is debug, go to Dodebug, run debug mode
If ""%1 "" = = "" Run "" Goto Dorun if%1 is run, go to Dorun, run normal mode
If ""%1 "" = = "" Start "" Goto Dostart if%1 is start, go to Dostart, start tomcat
If ""%1 "" = = "" Stop "" Goto dostop if%1 is stop, go to Dostop, close Tocmat
If ""%1 "" = = "" Version "" Goto Doversion If%1 is version, go to doversion, display the version number of Tomcat

echo Usage:catalina (Commands ...) If%1 does not have the above content, output the following lines and end
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 windows with Security Manager
echo Stop Stop Catalina
echo version what version of Tomcat is you running?
Goto END

:d Odebug
Shift moves the value in% 2 to%1
Set _execjava=%_runjdb% sets the variable _execjava to the value of the _RUNJDB variable
Set Debug_opts=-sourcepath "%catalina_home%\. \.. \jakarta-tomcat-catalina\catalina\src\share "
Setting the debug_opts variable

If not ""%1 "" = = ""-security "" Goto ExecCmd
If%1 is not-security, go to ExecCmd location

Shift moves the value in% 2 to%1
echo Using Security Manager outputs the line
Set Security_policy_file=%catalina_base%\conf\catalina.policy
Set the value of the Security_policy_file variable

Goto ExecCmd Go to execcmd location

:d Orun
Shift moves the value in% 2 to%1
If not ""%1 "" = = ""-security "" Goto ExecCmd if%1 is not-security, go to ExecCmd location
Shift moves the value in% 2 to%1
echo Using Security Manager outputs the line
Set Security_policy_file=%catalina_base%\conf\catalina.policy
Set the value of the Security_policy_file variable

Goto ExecCmd Go to execcmd location

:d Ostart
Shift moves the value in% 2 to%1
If not "%os%" = = "Windows_NT" goto notitle If the OS variable is not windows_nt, go to Notitle
Set _execjava=start "Tomcat"%_runjava% set the value of the _execjava variable
Goto Gottitle Go to gottitle location
: Notitle
Set _execjava=start%_runjava% Set the value of the _execjava variable
: Gottitle
If not ""%1 "" = = ""-security "" Goto ExecCmd if%1 is not-security, go to ExecCmd location
Shift moves the value in% 2 to%1
echo Using Security Manager outputs the line
Set Security_policy_file=%catalina_base%\conf\catalina.policy
Set the value of the Security_policy_file variable

Goto ExecCmd Go to execcmd location

:d Ostop
Shift moves the value in% 2 to%1
Set Action=stop set the ACTION's variable to stop
Set catalina_opts= set Catalina_opts is empty

Goto ExecCmd Go to execcmd location

:d Oversion Displays the Tomcat version number
%_execjava%-classpath "%catalina_home%\server\lib\catalina.jar" org.apache.catalina.util.ServerInfo execute the command
Goto End Ends The program

: ExecCmd
REM Get remaining unshifted command line arguments and save them in the
The following lines command parameters are stored in the Cmd_line_args variable

Set cmd_line_args=
: Setargs
If ""%1 "" = = "" "Goto Donesetargs
Set cmd_line_args=%cmd_line_args%%1
Shift
Goto Setargs
:d Onesetargs

REM Execute Java with the applicable properties
If not "%jpda%" = = "goto DOJPDA If JPDA variable is not empty, go to DOJPDA position
If not "%security_policy_file%" = = "goto dosecurity
If the security_policy_file variable is not empty, go to the dosecurity position

If none of the following commands are executed and the program ends
%_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
:d osecurity Execute the following command and end the program
%_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
:d OJPDA
If the security_policy_file variable is not empty, go to the DOSECURITYJPDA position, run the following command for NULL, and end the program

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
:d OSECURITYJPDA Execute the following command and end the program
%_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

End:

Catalina.bat What do you think the Windows program, you can double-click Run, is actually called the Java command to run the Bootstrap class. From the above code can be seen that Tomcat is really a pure Java program, the script eventually become directly using the Java Command Execution program, and our ordinary written Java program, no different. Just because Tomcat can use a wide variety of patterns (such as debug,security, etc.), and various parameters required, it is necessary to use scripts to execute.

If you want to see what command you are using, add two lines below the "if not"%security_policy_file% "= =" "Goto dosecurity" line.
echo%_execjava%%java_opts%%catalina_opts%%debug_opts%-djava.endorsed.dir .... (The following paragraph, is a line but too long, folded line)
Pause
The first line of the command is to print the words, the system will be in the% of the variables found in the value and output. The second line is to pause the program and you can restore it by any key.
Here is the result of my program printing:

Start "Tomcat" "C:\Program Files\java\jdk1.6.0_01\bin\java"-djava.util.logging.manager= Org.apache.juli.classloaderlogmanager-djava.util.logging.config.file= "C:\work\tomcat\conf\logging.properties"- xms128m-xmx512m-dfile.encoding=utf8-duser.timezone=gmt-djava.security.auth.login.config=c:\work\tomcat/conf/ jaas.config-djava.endorsed.dirs= "C:\work\tomcat\common\endorsed"-classpath "C:\Program files\java\jdk1.6.0_01\ Lib\tools.jar; C:\work\tomcat\bin\bootstrap.jar "-dcatalina.base=" C:\work\tomcat "-dcatalina.home=" C:\work\tomcat "- Djava.io.tmpdir= "C:\work\tomcat\temp" org.apache.catalina.startup.Bootstrap start

Start "Tomcat" is another window, window name is tomcat meaning, you can remove this part, finish the copy of your program print to the command line, click Enter, see if it is the same as running Tomcat.   Catalina.bat startup in real time, the various system variables are summarized, output to this command. Oh!

=========================================================================

There is no catalina.bat in the installed version of Tomcat, in fact these catalina.bat settings are the registry changes, the corresponding registry key values are as follows

Hkey_local_machine\software\apache Software Foundation\procrun 2.0\tomcat6\parameters\java\options

=========================================================================

When you use Myeclipse+tomcat to publish your project, you will often be prompted with the following message: [Org.apache.catalina.core.aprlifecyclelistener]-[info] the Apache Tomcat Native library which allows optimal performance in production environments is not found on the Java.library.path: (... Your system environment path ... )

When stopped, the following information appears
[Org.apache.catalina.core.aprlifecyclelistener]-[info] Failed shutdown of Apache portable Runtime

FIX: Installation configuration and use under Windows
1, first go to http://tomcat.heanet.ie/native/download compiled Tcnative-1.dll file, you can also download tomcat-native.zip yourself to compile
2, modify the Catalina.bat, plus
Set catalina_opts= "-djava.library.path=. /.. /apr/lib "
Because I put this DLL in the Apr/lib directory sibling to the Tomcat directory, the relative path is used. Or add DLLs to your system variable path, the simplest way is to put the Tcnative-1.dll file in the Tomcat Bin directory:)

After this is set up, the startup can see the following information:
[Org.apache.coyote.http11.http11aprprotocol]-[info] Initializing Coyote http/1.1 on http-9091
When stopped, the following information appears
[Org.apache.coyote.http11.http11aprprotocol]-[info] Pausing coyote http/1.1 on http-9091
......
[Org.apache.coyote.http11.http11aprprotocol]-[info] Stopping coyote http/1.1 on http-9091

This makes the configuration successful.

Catalina.bat detailed

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.