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
9 rem http://www.apache.org/licenses/LICENSE-2.0
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.
17 rem ---------------------------------------------------------------------------
18 rem NT Service Install/Uninstall script
20 rem Usage: service.bat install/remove [service_name [--rename]] [--user username]
23 rem install Install the service using default settings.
24 rem remove Remove the service from the system.
26 rem service_name (optional) The name to use for the service. If not specified,
27 rem Tomcat10 is used as the service name.
29 rem --rename (optional) Rename tomcat10.exe and tomcat10w.exe to match
30 rem the non-default service name.
32 rem username (optional) The name of the OS user to use to install/remove
33 rem the service (not the name of the OS user the
34 rem service will run as). If not specified, the current
36 rem ---------------------------------------------------------------------------
40 set "SELF=%~dp0%service.bat"
42 set DEFAULT_SERVICE_NAME=Tomcat10
43 set SERVICE_NAME=%DEFAULT_SERVICE_NAME%
45 set "CURRENT_DIR=%cd%"
47 rem Parse the arguments
48 if "x%1x" == "xx" goto displayUsage
51 if "x%1x" == "xx" goto checkEnv
53 if "x%1x" == "x/userx" goto runAsUser
54 if "x%1x" == "x--userx" goto runAsUser
57 if "x%1x" == "xx" goto checkEnv
58 if "x%1x" == "x--renamex" (
62 if "x%1x" == "xx" goto checkEnv
66 if "x%1x" == "xx" goto displayUsage
69 runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
72 rem Check the environment
75 rem Guess CATALINA_HOME if not defined
76 if not "%CATALINA_HOME%" == "" goto gotHome
77 set "CATALINA_HOME=%cd%"
78 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" goto gotHome
79 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" goto gotHome
80 rem CD to the upper dir
82 set "CATALINA_HOME=%cd%"
84 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
85 set "EXECUTABLE=%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"
88 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
89 set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
92 if "%DEFAULT_SERVICE_NAME%"== "%SERVICE_NAME%" (
93 echo The file %DEFAULT_SERVICE_NAME%.exe was not found...
95 echo Neither the %DEFAULT_SERVICE_NAME%.exe file nor the %SERVICE_NAME%.exe file was found...
97 echo Either the CATALINA_HOME environment variable is not defined correctly or
98 echo the incorrect service name has been used.
99 echo Both the CATALINA_HOME environment variable and the correct service name
100 echo are required to run this program.
105 rem Make sure prerequisite environment variables are set
106 if not "%JRE_HOME%" == "" goto gotJreHome
107 if not "%JAVA_HOME%" == "" goto gotJavaHome
108 echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
109 echo Service will try to guess them from the registry.
113 rem No JRE given, check if JAVA_HOME is usable as JRE_HOME
114 if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHomeAsJre
115 rem Use JAVA_HOME as JRE_HOME
116 set "JRE_HOME=%JAVA_HOME%"
120 echo The JAVA_HOME environment variable is not defined correctly.
121 echo JAVA_HOME=%JAVA_HOME%
122 echo NB: JAVA_HOME should point to a JDK not a JRE.
126 rem Check if we have a usable JRE
127 if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome
131 rem Needed at least a JRE
132 echo The JRE_HOME environment variable is not defined correctly
133 echo JRE_HOME=%JRE_HOME%
134 echo This environment variable is needed to run this program
138 if not "%CATALINA_BASE%" == "" goto gotBase
139 set "CATALINA_BASE=%CATALINA_HOME%"
142 rem Process the requested command
143 if /i %SERVICE_CMD% == install goto doInstall
144 if /i %SERVICE_CMD% == remove goto doRemove
145 if /i %SERVICE_CMD% == uninstall goto doRemove
146 echo Unknown parameter "%SERVICE_CMD%"
149 echo Usage: service.bat install/remove [service_name [--rename]] [--user username]
153 rem Remove the service
154 echo Removing the service '%SERVICE_NAME%' ...
155 echo Using CATALINA_BASE: "%CATALINA_BASE%"
157 "%EXECUTABLE%" //DS//%SERVICE_NAME% ^
158 --LogPath "%CATALINA_BASE%\logs"
159 if not errorlevel 1 goto removed
160 echo Failed removing '%SERVICE_NAME%' service
163 echo The service '%SERVICE_NAME%' has been removed
164 if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
165 rename "%SERVICE_NAME%.exe" "%DEFAULT_SERVICE_NAME%.exe"
166 rename "%SERVICE_NAME%w.exe" "%DEFAULT_SERVICE_NAME%w.exe"
171 rem Install the service
172 echo Installing the service '%SERVICE_NAME%' ...
173 echo Using CATALINA_HOME: "%CATALINA_HOME%"
174 echo Using CATALINA_BASE: "%CATALINA_BASE%"
175 echo Using JRE_HOME: "%JRE_HOME%"
177 rem Try to use the server jvm
178 set "JVM=%JRE_HOME%\bin\server\jvm.dll"
179 if exist "%JVM%" goto foundJvm
180 rem Try to use the client jvm
181 set "JVM=%JRE_HOME%\bin\client\jvm.dll"
182 if exist "%JVM%" goto foundJvm
183 echo Warning: Neither 'server' nor 'client' jvm.dll was found at JRE_HOME.
186 echo Using JVM: "%JVM%"
188 rem === IFA 2018/02/01 openoffice
\82Ì CLASSPATH
\82â
\81A
\8ag
\92£
\83t
\83H
\83\8b\83_(endorsed7.0)
\82Ì
\83N
\83\89\83X
\83p
\83X
\82ð
\92Ç
\89Á
\82µ
\82Ä
\82¨
\82«
\82Ü
\82·
\81B
\82±
\82ê
\82Å
\83\8c\83W
\83X
\83g
\83\8a\82É
\82à
\8f\91\82«
\8d\9e\82Ü
\82ê
\82Ü
\82·
\81B
189 rem set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar"
190 set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%OG_CLASSPATH%"
191 if not "%CATALINA_HOME%" == "%CATALINA_BASE%" set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
193 if "%SERVICE_STARTUP_MODE%" == "" set SERVICE_STARTUP_MODE=manual
194 if "%JvmMs%" == "" set JvmMs=128
195 if "%JvmMx%" == "" set JvmMx=256
197 if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
198 if "x%RENAME%x" == "x--renamex" (
199 rename "%DEFAULT_SERVICE_NAME%.exe" "%SERVICE_NAME%.exe"
200 rename "%DEFAULT_SERVICE_NAME%w.exe" "%SERVICE_NAME%w.exe"
201 set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
205 "%EXECUTABLE%" //IS//%SERVICE_NAME% ^
206 --Description "Apache Tomcat 10.1.10 Server - https://tomcat.apache.org/" ^
207 --DisplayName "Apache Tomcat 10.1 %SERVICE_NAME%" ^
208 --Install "%EXECUTABLE%" ^
209 --LogPath "%CATALINA_BASE%\logs" ^
212 --Classpath "%CLASSPATH%" ^
216 --StartPath "%CATALINA_HOME%" ^
217 --StopPath "%CATALINA_HOME%" ^
218 --StartClass org.apache.catalina.startup.Bootstrap ^
219 --StopClass org.apache.catalina.startup.Bootstrap ^
220 --StartParams start ^
222 --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;%JvmArgs%" ^
223 --JvmOptions9 "--add-opens=java.base/java.lang=ALL-UNNAMED#--add-opens=java.base/java.io=ALL-UNNAMED#--add-opens=java.base/java.util=ALL-UNNAMED#--add-opens=java.base/java.util.concurrent=ALL-UNNAMED#--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED" ^
224 --Startup "%SERVICE_STARTUP_MODE%" ^
227 if not errorlevel 1 goto installed
228 echo Failed installing '%SERVICE_NAME%' service
231 echo The service '%SERVICE_NAME%' has been installed.