blob: e70c14a4166b346b97ce388a7507a469e0f7409e [file] [log] [blame]
刘洪青65827522016-10-19 16:10:39 +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
17rem ---------------------------------------------------------------------------
18rem Start/Stop Script for the CATALINA Server
19rem
20rem Environment Variable Prerequisites
21rem
22rem Do not set the variables in this script. Instead put them into a script
23rem setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
24rem
刘洪青8d26a3c2018-02-28 18:16:21 +080025rem WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:
26rem Note that the environment variables that affect the behavior of this
27rem script will have no effect at all on Windows Services. As such, any
28rem local customizations made in a CATALINA_BASE/bin/setenv.bat script
29rem will also have no effect on Tomcat when launched as a Windows Service.
30rem The configuration that controls Windows Services is stored in the Windows
31rem Registry, and is most conveniently maintained using the "tomcatXw.exe"
32rem maintenance utility, where "X" is the major version of Tomcat you are
33rem running.
34rem
刘洪青65827522016-10-19 16:10:39 +080035rem CATALINA_HOME May point at your Catalina "build" directory.
36rem
37rem CATALINA_BASE (Optional) Base directory for resolving dynamic portions
38rem of a Catalina installation. If not present, resolves to
39rem the same directory that CATALINA_HOME points to.
40rem
41rem CATALINA_OPTS (Optional) Java runtime options used when the "start",
42rem "run" or "debug" command is executed.
43rem Include here and not in JAVA_OPTS all options, that should
44rem only be used by Tomcat itself, not by the stop process,
45rem the version command etc.
46rem Examples are heap size, GC logging, JMX ports etc.
47rem
48rem CATALINA_TMPDIR (Optional) Directory path location of temporary directory
49rem the JVM should use (java.io.tmpdir). Defaults to
50rem %CATALINA_BASE%\temp.
51rem
52rem JAVA_HOME Must point at your Java Development Kit installation.
53rem Required to run the with the "debug" argument.
54rem
55rem JRE_HOME Must point at your Java Runtime installation.
56rem Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
57rem are both set, JRE_HOME is used.
58rem
59rem JAVA_OPTS (Optional) Java runtime options used when any command
60rem is executed.
61rem Include here and not in CATALINA_OPTS all options, that
62rem should be used by Tomcat and also by the stop process,
63rem the version command etc.
64rem Most options should go into CATALINA_OPTS.
65rem
66rem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
67rem containing some jars in order to allow replacement of APIs
68rem created outside of the JCP (i.e. DOM and SAX from W3C).
69rem It can also be used to update the XML parser implementation.
刘洪青8d26a3c2018-02-28 18:16:21 +080070rem Note that Java 9 no longer supports this feature.
刘洪青65827522016-10-19 16:10:39 +080071rem Defaults to $CATALINA_HOME/endorsed.
72rem
73rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"
74rem command is executed. The default is "dt_socket".
75rem
76rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
77rem command is executed. The default is 8000.
78rem
79rem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"
80rem command is executed. Specifies whether JVM should suspend
81rem execution immediately after startup. Default is "n".
82rem
83rem JPDA_OPTS (Optional) Java runtime options used when the "jpda start"
84rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
85rem and JPDA_SUSPEND are ignored. Thus, all required jpda
86rem options MUST be specified. The default is:
87rem
88rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
89rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
90rem
91rem JSSE_OPTS (Optional) Java runtime options used to control the TLS
92rem implementation when JSSE is used. Default is:
93rem "-Djdk.tls.ephemeralDHKeySize=2048"
94rem
95rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file
96rem Example (all one line)
97rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
98rem
99rem LOGGING_MANAGER (Optional) Override Tomcat's logging manager
100rem Example (all one line)
101rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
102rem
103rem TITLE (Optional) Specify the title of Tomcat window. The default
104rem TITLE is Tomcat if it's not specified.
105rem Example (all one line)
106rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
107rem ---------------------------------------------------------------------------
108
109setlocal
110
111rem Suppress Terminate batch job on CTRL+C
112if not ""%1"" == ""run"" goto mainEntry
113if "%TEMP%" == "" goto mainEntry
114if exist "%TEMP%\%~nx0.run" goto mainEntry
115echo Y>"%TEMP%\%~nx0.run"
116if not exist "%TEMP%\%~nx0.run" goto mainEntry
117echo Y>"%TEMP%\%~nx0.Y"
118call "%~f0" %* <"%TEMP%\%~nx0.Y"
119rem Use provided errorlevel
120set RETVAL=%ERRORLEVEL%
121del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1
122exit /B %RETVAL%
123:mainEntry
124del /Q "%TEMP%\%~nx0.run" >NUL 2>&1
125
126rem Guess CATALINA_HOME if not defined
127set "CURRENT_DIR=%cd%"
128if not "%CATALINA_HOME%" == "" goto gotHome
129set "CATALINA_HOME=%CURRENT_DIR%"
130if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
131cd ..
132set "CATALINA_HOME=%cd%"
133cd "%CURRENT_DIR%"
134:gotHome
135
136if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
137echo The CATALINA_HOME environment variable is not defined correctly
138echo This environment variable is needed to run this program
139goto end
140:okHome
141
142rem Copy CATALINA_BASE from CATALINA_HOME if not defined
143if not "%CATALINA_BASE%" == "" goto gotBase
144set "CATALINA_BASE=%CATALINA_HOME%"
145:gotBase
146
147rem Ensure that any user defined CLASSPATH variables are not used on startup,
148rem but allow them to be specified in setenv.bat, in rare case when it is needed.
149set CLASSPATH=
150
151rem Get standard environment variables
152if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
153call "%CATALINA_BASE%\bin\setenv.bat"
154goto setenvDone
155:checkSetenvHome
156if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
157:setenvDone
158
159rem Get standard Java environment variables
160if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
161echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
162echo This file is needed to run this program
163goto end
164:okSetclasspath
165call "%CATALINA_HOME%\bin\setclasspath.bat" %1
166if errorlevel 1 goto end
167
168rem Add on extra jar file to CLASSPATH
169rem Note that there are no quotes as we do not want to introduce random
170rem quotes into the CLASSPATH
171if "%CLASSPATH%" == "" goto emptyClasspath
172set "CLASSPATH=%CLASSPATH%;"
173:emptyClasspath
174set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"
175
176if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
177set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
178:gotTmpdir
179
180rem Add tomcat-juli.jar to classpath
181rem tomcat-juli.jar can be over-ridden per instance
182if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome
183set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"
184goto juliClasspathDone
185:juliClasspathHome
186set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
187:juliClasspathDone
188
189if not "%JSSE_OPTS%" == "" goto gotJsseOpts
190set JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048"
191:gotJsseOpts
192set "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"
193
194if not "%LOGGING_CONFIG%" == "" goto noJuliConfig
195set LOGGING_CONFIG=-Dnop
196if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig
197set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
198:noJuliConfig
刘洪青65827522016-10-19 16:10:39 +0800199
200if not "%LOGGING_MANAGER%" == "" goto noJuliManager
201set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
202:noJuliManager
刘洪青8d26a3c2018-02-28 18:16:21 +0800203
204rem Java 9 no longer supports the java.endorsed.dirs
205rem system property. Only try to use it if
206rem JAVA_ENDORSED_DIRS was explicitly set
207rem or CATALINA_HOME/endorsed exists.
208set ENDORSED_PROP=ignore.endorsed.dirs
209if "%JAVA_ENDORSED_DIRS%" == "" goto noEndorsedVar
210set ENDORSED_PROP=java.endorsed.dirs
211goto doneEndorsed
212:noEndorsedVar
213if not exist "%CATALINA_HOME%\endorsed" goto doneEndorsed
214set ENDORSED_PROP=java.endorsed.dirs
215:doneEndorsed
216
217rem Configure JAVA 9 specific start-up parameters
218set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.base/java.lang=ALL-UNNAMED"
219set "JDK_JAVA_OPTIONS=%JDK_JAVA_OPTIONS% --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
刘洪青65827522016-10-19 16:10:39 +0800220
221rem ----- Execute The Requested Command ---------------------------------------
222
223echo Using CATALINA_BASE: "%CATALINA_BASE%"
224echo Using CATALINA_HOME: "%CATALINA_HOME%"
225echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
226if ""%1"" == ""debug"" goto use_jdk
227echo Using JRE_HOME: "%JRE_HOME%"
228goto java_dir_displayed
229:use_jdk
230echo Using JAVA_HOME: "%JAVA_HOME%"
231:java_dir_displayed
232echo Using CLASSPATH: "%CLASSPATH%"
233
234set _EXECJAVA=%_RUNJAVA%
235set MAINCLASS=org.apache.catalina.startup.Bootstrap
236set ACTION=start
237set SECURITY_POLICY_FILE=
238set DEBUG_OPTS=
239set JPDA=
240
241if not ""%1"" == ""jpda"" goto noJpda
242set JPDA=jpda
243if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
244set JPDA_TRANSPORT=dt_socket
245:gotJpdaTransport
246if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
247set JPDA_ADDRESS=8000
248:gotJpdaAddress
249if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
250set JPDA_SUSPEND=n
251:gotJpdaSuspend
252if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
253set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
254:gotJpdaOpts
255shift
256:noJpda
257
258if ""%1"" == ""debug"" goto doDebug
259if ""%1"" == ""run"" goto doRun
260if ""%1"" == ""start"" goto doStart
261if ""%1"" == ""stop"" goto doStop
262if ""%1"" == ""configtest"" goto doConfigTest
263if ""%1"" == ""version"" goto doVersion
264
265echo Usage: catalina ( commands ... )
266echo commands:
267echo debug Start Catalina in a debugger
268echo debug -security Debug Catalina with a security manager
269echo jpda start Start Catalina under JPDA debugger
270echo run Start Catalina in the current window
271echo run -security Start in the current window with security manager
272echo start Start Catalina in a separate window
273echo start -security Start in a separate window with security manager
274echo stop Stop Catalina
275echo configtest Run a basic syntax check on server.xml
276echo version What version of tomcat are you running?
277goto end
278
279:doDebug
280shift
281set _EXECJAVA=%_RUNJDB%
282set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
283if not ""%1"" == ""-security"" goto execCmd
284shift
285echo Using Security Manager
286set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
287goto execCmd
288
289:doRun
290shift
291if not ""%1"" == ""-security"" goto execCmd
292shift
293echo Using Security Manager
294set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
295goto execCmd
296
297:doStart
298shift
299if "%TITLE%" == "" set TITLE=Tomcat
300set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
301if not ""%1"" == ""-security"" goto execCmd
302shift
303echo Using Security Manager
304set "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"
305goto execCmd
306
307:doStop
308shift
309set ACTION=stop
310set CATALINA_OPTS=
311goto execCmd
312
313:doConfigTest
314shift
315set ACTION=configtest
316set CATALINA_OPTS=
317goto execCmd
318
319:doVersion
320%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
321goto end
322
323
324:execCmd
325rem Get remaining unshifted command line arguments and save them in the
326set CMD_LINE_ARGS=
327:setArgs
328if ""%1""=="""" goto doneSetArgs
329set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
330shift
331goto setArgs
332:doneSetArgs
333
334rem Execute Java with the applicable properties
335if not "%JPDA%" == "" goto doJpda
336if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
刘洪青8d26a3c2018-02-28 18:16:21 +0800337%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
刘洪青65827522016-10-19 16:10:39 +0800338goto end
339:doSecurity
刘洪青8d26a3c2018-02-28 18:16:21 +0800340%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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%
刘洪青65827522016-10-19 16:10:39 +0800341goto end
342:doJpda
343if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
刘洪青8d26a3c2018-02-28 18:16:21 +0800344%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
刘洪青65827522016-10-19 16:10:39 +0800345goto end
346:doSecurityJpda
刘洪青8d26a3c2018-02-28 18:16:21 +0800347%_EXECJAVA% %LOGGING_CONFIG% %LOGGING_MANAGER% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -D%ENDORSED_PROP%="%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%
刘洪青65827522016-10-19 16:10:39 +0800348goto end
349
350:end