Tomcat Learning Notes (i)--startup.bat and Shutdown.bat

Source: Internet
Author: User
Tags goto

Recently in the study of the Zhang Xiaoxiang: Teacher's tomcat video, is known after sleep it, in order to review the consolidation, I put some points down.

Operating system: Win7 flagship 64-bit

Tomcat version: Apache-tomcat-7.0.23-windows-x64.zip (direct pressure use)

Tomcat Extract directory: D:\tomcat-7.0.23 ("Tomcat extract directory" Changes according to the circumstances)

I. Setting up the Tomcat operating environment

Tomcat run needs to set JAVA_HOME environment variable

There are two ways to set up a Java_home variable:

Method 1. On the "computer"--Right click "Properties"--click "Advanced System Variables"--under the "Advanced" tab--click "Environment Variables"--click the "New" button under "System Variables"

Enter "variable name": Java_home

Input variable Value: D:\jdk1.7.0_01 (this is the installation directory for my JDK)

Then keep clicking the OK button

Method 2. Locate the Startup.bat batch file in the D:\tomcat-7.0.23\bin directory and open it in text mode

Add code set java_home=d:\jdk1.7.0_01 after the first line of code

As follows: @echo offset java_home=d:\jdk1.7.0_01

Second, the environment variable test:

Run cmd down and go to the D:\tomcat-7.0.23\bin directory to run Startup.bat

Tomcat pops up a new run box that shows Balabala a bunch of running status echoes, and if there are no errors and warnings in the Echo text message, the tomcat boot load is OK

Browser run: http://localhost:8080/pops up pretty Tomcat home page to show that Tomcat is running successfully

Three, Startup.bat batch processing document detailed explanation

Hint: I am in cmd, go to D:\tomcat-7.0.23\bin directory run Startup.bat, so my current working directory is: D:\tomcat-7.0.23\bin, take this directory as an example to explain

Tomcat Extract Directory: D:\tomcat-7.0.23

@echo off					//row command effect: Show only the following command execution results, do not display the command itself
If "%os%" = = "Windows_NT" setlocal		//If native OS is windows_nt set native environment variables
REM Guess catalina_home if not defined//		is comment code: Determines whether the CATALINA_HOME environment variable has been configured
set "current_dir=%cd%"				// Set the Current_dir variable (current working directory) as: D:\tomcat-7.0.23\bin if not  
%catalina_home% "= =" goto gothome	//If Catalina_ is configured Home environment variable Jump execution Gothome
Set "catalina_home=%current_dir%"          	 //If no settings are set, the Catalina_home variable is: D:\tomcat-7.0.23\bin if  
exist "%catalina_ Home%\bin\catalina.bat goto Okhome//View the presence of Catalina.bat files under the current working directory \ Bin directory (that is, D:\tomcat-7.0.23\bin\bin) if there is a jump okhome
CD..					Back to the parent subdirectory, that is: D:\tomcat-7.0.23, at which time the current working directory has changed to: D:\tomcat-7.0.23
Set "catalina_home=%cd%" 		//Change Catalina_ The home variable value is: D:\tomcat-7.0.23
cd "%current_dir%"			//switch to current working directory: D:\tomcat-7.0.23

: gothome if
exist "%catalina_home%\bin\catalina.bat" goto okhome			//If Catalina.bat batch file is found, jump Okhome
echo the CATALINA_HOME environment variable is not defined correctly    //Cannot find Catalina.bat file, display error message, then end
echo this environment variable is needed       	to run the current directory for executing startup.bat in CMD is not: "Tomcat extract Directory" and "Tomcat extract directory \ Bin" This error message is prompted
Goto END
This shows that Catalina.bat is really the batch program that performs Tomcat startup and shutdown
When executing Startup.bat, if the Startup.bat file is not in the "Tomcat extract Directory" or "Tomcat extract directory \ Bin" Directory
will prompt catalina_home error message  
: Okhome
Set "Executable=%catalina_home%\bin\catalina.bat"   //So Catalina.bat file has been identified, now set executable (execution file) environment variable
REM Check that target executable exists
If exist "%executable%" goto okexec      	 //If executable variable has been set successfully, jump Okexec execute
echo Cannot find "%executable%"                //otherwise prompt for Catalina.bat execution file not found
echo this file are needed to run the This program
Goto end
: Okexec
rem Get remaining unshifted command line arguments and save them in the
set cmd_line_args=   				 //Clear Cmd_lin E_args the original value of the environment variable
: Setargs if
"%1" "= =" "" Goto Donesetargs		 //If the second argument is an empty jump Donesetargs, that is, the passed parameters have been completed  
Set cmd_line_args=%cmd_line_args%%1   		 //Add parameters to Cmd_line_args, separated by spaces
Shift                         			 //truncate the first argument so that the second argument becomes the first argument
Goto Setargs
  the above 5 lines of code function is to open all the parameters by space, and assign value Cmd_line_args
:d Onesetargs
Call "%executable%" start%cmd_line_args%  	//Open a new window, execute the catalina.bat batch file represented by the executable environment variable and cmd_ Parameters represented by Line_args
:						End//Ending


Summarize:

1. The role of Startup.bat is primarily to check the Catalina.bat execution environment and invoke Catalina.bat batch files

2. The content of the Shutdown.bat file and Startup.bat file is only a little different, that is, the penultimate line of code, by modifying the execution parameter start to stop and to the Catalina.bat to implement Tomcat shutdown

Add:

1. rem

There is rem in front of the code: the code being decorated is an annotation explanatory text

2. @

Code preceded by @: The modified code executes, showing only execution results, not displaying the command itself

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.