catalina.bat 16 KB

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