blob: 122b085aeda61852682fd852ddf8a74f144b6b1a [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001@echo off
2rem Licensed to the Apache Software Foundation (ASF) under one or more
3rem contributor license agreements. See the NOTICE file distributed with
4rem this work for additional information regarding copyright ownership.
5rem The ASF licenses this file to You under the Apache License, Version 2.0
6rem (the "License"); you may not use this file except in compliance with
7rem the License. You may obtain a copy of the License at
8rem
9rem http://www.apache.org/licenses/LICENSE-2.0
10rem
11rem Unless required by applicable law or agreed to in writing, software
12rem distributed under the License is distributed on an "AS IS" BASIS,
13rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14rem See the License for the specific language governing permissions and
15rem limitations under the License.
16
17if "%OS%" == "Windows_NT" setlocal
18rem ---------------------------------------------------------------------------
19rem Start/Stop Script for the CATALINA Server
20rem
21rem Environment Variable Prerequisites
22rem
23rem CATALINA_HOME May point at your Catalina "build" directory.
24rem
25rem CATALINA_BASE (Optional) Base directory for resolving dynamic portions
26rem of a Catalina installation. If not present, resolves to
27rem the same directory that CATALINA_HOME points to.
28rem
29rem CATALINA_OPTS (Optional) Java runtime options used when the "start",
30rem or "run" command is executed.
31rem
32rem CATALINA_TMPDIR (Optional) Directory path location of temporary directory
33rem the JVM should use (java.io.tmpdir). Defaults to
34rem %CATALINA_BASE%\temp.
35rem
36rem JAVA_HOME Must point at your Java Development Kit installation.
37rem Required to run the with the "debug" argument.
38rem
39rem JRE_HOME Must point at your Java Runtime installation.
40rem Defaults to JAVA_HOME if empty.
41rem
42rem JAVA_OPTS (Optional) Java runtime options used when the "start",
43rem "stop", or "run" command is executed.
44rem
45rem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
46rem containing some jars in order to allow replacement of APIs
47rem created outside of the JCP (i.e. DOM and SAX from W3C).
48rem It can also be used to update the XML parser implementation.
49rem Defaults to $CATALINA_HOME/endorsed.
50rem
51rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
52rem command is executed. The default is "dt_socket".
53rem
54rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
55rem command is executed. The default is 8000.
56rem
57rem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
58rem command is executed. Specifies whether JVM should suspend
59rem execution immediately after startup. Default is "n".
60rem
61rem JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
62rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
63rem and JPDA_SUSPEND are ignored. Thus, all required jpda
64rem options MUST be specified. The default is:
65rem
66rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
67rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
68rem
69rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file
70rem Example (all one line)
71rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
72rem
73rem LOGGING_MANAGER (Optional) Override Tomcat's logging manager
74rem Example (all one line)
75rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
76rem
77rem TITLE (Optional) Specify the title of Tomcat window. The default
78rem TITLE is Tomcat if it's not specified.
79rem Example (all one line)
80rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
81rem ---------------------------------------------------------------------------
82
83rem Guess CATALINA_HOME if not defined
84set "CURRENT_DIR=%cd%"
85if not "%CATALINA_HOME%" == "" goto gotHome
86set "CATALINA_HOME=%CURRENT_DIR%"
87if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
88cd ..
89set "CATALINA_HOME=%cd%"
90cd "%CURRENT_DIR%"
91:gotHome
92if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
93echo The CATALINA_HOME environment variable is not defined correctly
94echo This environment variable is needed to run this program
95goto end
96:okHome
97
98rem Copy CATALINA_BASE from CATALINA_HOME if not defined
99if not "%CATALINA_BASE%" == "" goto gotBase
100set "CATALINA_BASE=%CATALINA_HOME%"
101:gotBase
102
103rem Ensure that any user defined CLASSPATH variables are not used on startup,
104rem but allow them to be specified in setenv.bat, in rare case when it is needed.
105set CLASSPATH=
106
107rem Get standard environment variables
108if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
109call "%CATALINA_BASE%\bin\setenv.bat"
110goto setenvDone
111:checkSetenvHome
112if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
113:setenvDone
114
115rem Get standard Java environment variables
116if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
117echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
118echo This file is needed to run this program
119goto end
120:okSetclasspath
121set "BASEDIR=%CATALINA_HOME%"
122call "%CATALINA_HOME%\bin\setclasspath.bat" %1
123if errorlevel 1 goto end
124
125if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
126set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
127:gotTmpdir
128
129rem Add tomcat-juli.jar and bootstrap.jar to classpath
130rem tomcat-juli.jar can be over-ridden per instance
131rem Note that there are no quotes as we do not want to introduce random
132rem quotes into the CLASSPATH
133if "%CLASSPATH%" == "" goto emptyClasspath
134set "CLASSPATH=%CLASSPATH%;"
135:emptyClasspath
136if "%CATALINA_BASE%" == "%CATALINA_HOME%" goto juliClasspathHome
137if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
138set "CLASSPATH=%CLASSPATH%%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\bootstrap.jar"
139goto juliClasspathDone
140:juliClasspathHome
141set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
142:juliClasspathDone
143
144if not "%LOGGING_CONFIG%" == "" goto noJuliConfig
145set LOGGING_CONFIG=-Dnop
146if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
147set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
148:noJuliConfig
149set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%
150
151if not "%LOGGING_MANAGER%" == "" goto noJuliManager
152set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
153:noJuliManager
154set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%
155
156rem ----- Execute The Requested Command ---------------------------------------
157
158echo Using CATALINA_BASE: "%CATALINA_BASE%"
159echo Using CATALINA_HOME: "%CATALINA_HOME%"
160echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
161if ""%1"" == ""debug"" goto use_jdk
162echo Using JRE_HOME: "%JRE_HOME%"
163goto java_dir_displayed
164:use_jdk
165echo Using JAVA_HOME: "%JAVA_HOME%"
166:java_dir_displayed
167echo Using CLASSPATH: "%CLASSPATH%"
168
169set _EXECJAVA=%_RUNJAVA%
170set MAINCLASS=org.apache.catalina.startup.Bootstrap
171set ACTION=start
172set SECURITY_POLICY_FILE=
173set DEBUG_OPTS=
174set JPDA=
175
176if not ""%1"" == ""jpda"" goto noJpda
177set JPDA=jpda
178if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
179set JPDA_TRANSPORT=dt_socket
180:gotJpdaTransport
181if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
182set JPDA_ADDRESS=8000
183:gotJpdaAddress
184if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
185set JPDA_SUSPEND=n
186:gotJpdaSuspend
187if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
188set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
189:gotJpdaOpts
190shift
191:noJpda
192
193if ""%1"" == ""debug"" goto doDebug
194if ""%1"" == ""run"" goto doRun
195if ""%1"" == ""start"" goto doStart
196if ""%1"" == ""stop"" goto doStop
197if ""%1"" == ""version"" goto doVersion
198
199echo Usage: catalina ( commands ... )
200echo commands:
201echo debug Start Catalina in a debugger
202echo debug -security Debug Catalina with a security manager
203echo jpda start Start Catalina under JPDA debugger
204echo run Start Catalina in the current window
205echo run -security Start in the current window with security manager
206echo start Start Catalina in a separate window
207echo start -security Start in a separate window with security manager
208echo stop Stop Catalina
209echo version What version of tomcat are you running?
210goto end
211
212:doDebug
213shift
214set _EXECJAVA=%_RUNJDB%
215set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
216if not ""%1"" == ""-security"" goto execCmd
217shift
218echo Using Security Manager
219set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
220goto execCmd
221
222:doRun
223shift
224if not ""%1"" == ""-security"" goto execCmd
225shift
226echo Using Security Manager
227set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
228goto execCmd
229
230:doStart
231shift
232if not "%OS%" == "Windows_NT" goto noTitle
233if "%TITLE%" == "" set TITLE=Tomcat
234set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
235goto gotTitle
236:noTitle
237set _EXECJAVA=start %_RUNJAVA%
238:gotTitle
239if not ""%1"" == ""-security"" goto execCmd
240shift
241echo Using Security Manager
242set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
243goto execCmd
244
245:doStop
246shift
247set ACTION=stop
248set CATALINA_OPTS=
249goto execCmd
250
251:doVersion
252%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
253goto end
254
255
256:execCmd
257rem Get remaining unshifted command line arguments and save them in the
258set CMD_LINE_ARGS=
259:setArgs
260if ""%1""=="""" goto doneSetArgs
261set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
262shift
263goto setArgs
264:doneSetArgs
265
266rem Execute Java with the applicable properties
267if not "%JPDA%" == "" goto doJpda
268if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
269%_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%
270goto end
271:doSecurity
272%_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%
273goto end
274:doJpda
275if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
276%_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%
277goto end
278:doSecurityJpda
279%_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%
280goto end
281
282:end