Tomcat8 source code analysis 2 -- STARTUP script Catalina. bat

Source: Internet
Author: User

There is a blog talking very well: http://blog.csdn.net/flyliuweisky547/article/details/22753383

Below is the code I added with comments

@ Echo offrem: The environment modification is localized. The setlocal to endlocal command does not have an impression on the environment modification. The Code setlocalrem after endlocal is difficult to understand. It should be deleted from temporary files. if not "" % 1 "" = "" Run "" Goto mainentryif "% Temp %" = "" Goto mainentryif exist "% Temp % \ % ~ Nx0.run "Goto 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> & 1 exit/B % retval % REM here mainentry, gothome, okhome and startup. similarly in bat, set catalina_base to catalina_home: mainentrydel/Q "% Temp % \ % ~ Nx0.run "> NUL 2> & 1 Set" current_dir = % Cd % "if not" % catalina_home % "=" "Goto gothomeset" catalina_home = % current_dir % "If exist" % catalina_home % \ bin \ Catalina. bat "Goto okhommcm .. set "catalina_home = % Cd %" cd "% current_dir %": gothomeif exist "% catalina_home % \ bin \ Catalina. bat "Goto okhomeecho the catalina_home environment variable is not defined correctlyecho this environment variable is needed to run this Programgoto end: okhomerem copy catalina_base from catalina_home if not definedif not "% catalina_base %" = "" Goto gotbaseset "catalina_base = % catalina_home %" REM "% Category :; = % "indicates replacing"; "blank character" "In catalina_home". If ";" is not found in catalina_home, jump to homenosemicolon and exit: gotbaseif "% catalina_home %" = "% catalina_home :;=%" Goto homenosemicolonecho using catalina_home: "% catalina_home %" Echo unable to start As catalina_home contains a semicolon (;) charactergoto endrem is similar to the above. Check whether ";" exists in catalina_base and exit.: catalog "% catalina_base %" = "% catalina_base :;=%" Goto specify using catalina_base: "% catalina_base %" Echo unable to start as catalina_base contains a semicolon (;) charactergoto endrem sets the environment variable classpath to null REM if catalina_base does not exist setenv. BAT, the system will jump to the checksetenvhome and run the command to check whether Yes, execution of REM exists. If catalina_base has setenv. bat, execute REM to jump to setenvdone: basenosemicolonset classpath = if not exist "% catalina_base % \ bin \ setenv. bat "Goto checksetenvhomecall" % catalina_base % \ bin \ setenv. bat "Goto setenvdone: checksetenvhomeif exist" % catalina_home % \ bin \ setenv. bat "call" % catalina_home % \ bin \ setenv. bat "REM if setclasspath. bat exists. Execute it (mainly set java_home ).: setenvdoneif exist "% catalina_home % \ bin \ setclassp Ath. bat "Goto oksetclasspathecho cannot find" % catalina_home % \ bin \ setclasspath. bat "echo this file is needed to run this programgoto endrem execute setclasspath. bat. This bat mainly sets java_homerem. If classpath is empty, jump to emptyclasspath REM. Otherwise, add a semicolon to it and then jump to emptyclasspath: oksetclasspathcall "% catalina_home % \ bin \ setclasspath. bat "% 1if errorlevel 1 goto endif" % classpath % "=" "Goto emptyclasspathset" classpath = % classpath %; "REM will Bootstrap. add jar to classpath. catalina_tmpdir is not empty. Jump to gottmpdirrem. Otherwise, catalina_tmpdir is % catalina_base % \ Temp: alias "classpath = % classpath % catalina_home % \ bin \ Bootstrap. jar "if not" % catalina_tmpdir % "=" "Goto gottmpdirset" catalina_tmpdir = % catalina_base % \ Temp "REM if there is no tomcat-juli.jar under catalina_base, jump to category otherwise set tomcat-juli.jar to classpath, jump to juliclasspathdone: gottmpdirif not Exist "% catalina_base % \ bin \ tomcat-juli.jar" Goto juliclasspathhomeset "classpath = % classpath %; % catalina_base % \ bin \ tomcat-juli.jar" Goto handle no tomcat-juli.jar under catalina_base, find from catalina_home and add classpath: juliclasspathhomeset "classpath = % classpath %; % catalina_home % \ bin \ tomcat-juli.jar" REM to configure the log parameters for the Java command: juliclasspathdoneif not "% logging_config %" = "" Goto nojuliconfigset logging_c Onfig =-dnopif not exist "% catalina_base % \ conf \ Logging. properties "Goto nojuliconfigset logging_config =-djava. util. logging. config. file = "% catalina_base % \ conf \ Logging. properties ": nojuliconfigset java_opts = % java_opts % logging_config % if not" % logging_manager % "=" "Goto nojulimanagerset logging_manager =-djava. util. logging. manager = org. apache. juli. classloaderlogmanager: nojulimanagerset java_opts = % Java _ Opts % logging_manager % REM ----- execute the requested command cancel echo using catalina_base: "% catalina_base %" echo using catalina_home: "% catalina_home %" echo using catalina_tmpdir: "% catalina_tmpdir %" REM output information if "" % 1 "" = "debug" "Goto use_jdkecho using jre_home:" % jre_home % "Goto java_dir_displayed: Using using java_home: "% java_home %" REM _ runjava in setclasspa Th.batset, which is the main class for setting the REM path of java.exe, and the default parameter.: 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 = REM if the first parameter of the command line is JPDA, configure the JPDA parameter and move the parameter to the left. (JPDA is mainly used for remote debugging) if not "" % 1 "" = "" JPDA "" Goto nojpdaset JPDA = jpdaif not "% jpda_transport %" = "" Goto gotjpdatransportset jpda_t Ransport = dt_socket: gotjpdatransportif not "% jpda_address %" = "" Goto export jpda_address = localhost: 8000: Does not "% jpda_suspend %" = "" Goto export jpda_suspend = N: gotjpdasuspendif not "% jpda_opts %" = "" Goto gotjpdaoptsset jpda_opts =-agentlib: jdwp = transport = % jpda_transport %, address = % jpda_address %, Server = Y, suspend = % jpda_suspend %: gotjpdaoptsshiftrem redirects to nojp based on the corresponding command Daif "" % 1 "" = "" debug "Goto dodebugif" % 1 "" = "" Run "" Goto dorunif "" % 1 "" =" "Start" "Goto dostartif" "% 1" "=" "Stop" "Goto dostopif" "% 1" "=" "configtest" "Goto doconfigtestif" "% 1 "" = "" version "" Goto doversionecho usage: catalina (commands ...) echo commands: Echo debug start Catalina in a debuggerecho debug-security debug Catalina with a security managerecho JPDA start Catalina Under JPDA debuggerecho run start Catalina in the current region wecho run-security start in the current window with security managerecho start Catalina in a separate restart wecho start-security start in a separate window with security managerecho stop stop catalinaecho configtest run a basic syntax check on server. xmlecho version what version of Tomcat are you running? Goto endrem parameter shift left, callback path), debug_opts, security_policy_file, jump to execcmd: Export _ 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 execcmdrem parameter shifts left, sets security_policy_file and redirects to execcmd: dorunshiftif not "" % 1 "" = ""-Security "" Goto execcmdshiftecho using security managerset "security_policy_file = % catalina_base % \ conf \ Catalina. policy "Goto execcmdrem parameter shifts left, SET command line title to Tomcat, SET _ execjava to" start Tomcat xxx/java.exe, jump to execcmd: dostartshiftif "% title %" = "" set Title = atatset _ execjava = start "% title %" % _ runjava % if not "" % 1 "" = ""- security "" Goto execcmdshiftecho using security managerset "security_policy_file = % catalina_base % \ conf \ Catalina. policy "Goto execcmdrem action is set to stop, jump to execcmd: dostopshiftset action = stopset catalina_opts = goto execcmdrem no longer -. -: doconfigtestshiftset action = configtestset catalina_opts = goto execcmdrem doesn't play anymore -. -: doversion % _ execjava %-classpath "% catalina_home % \ Lib \ Catalina. jar "org. apache. catalina. util. serverinfogoto end: execcmdset parameters = REM loop to get all parameters to parameters: setargsif "" % 1 "" = "Goto donesetargsset parameters = % pai_line_args % 1 shiftgoto setargsrem dojpda, dosecurity does not enable REM to execute the start xxx/java.exe parameter: donesetargsif not "% JPDA %" = "" Goto dojpdaif not "% region %" = "" 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: 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 % %%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

Tomcat is controlled based on parameters. For startup, classpath, log parameters, security parameters, and so on are configured. The start java.exe parameter will eventually be pulled.

Tomcat8 source code analysis 2 -- STARTUP script Catalina. bat

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.