@echo off rem Licensed to the Apache Software Foundation (ASF) under one or more rem contributor license agreements. See the NOTICE file distributed with rem this work for additional information regarding copyright ownership. rem The ASF licenses this file to You under the Apache License, Version 2.0 rem (the "License"); you may not use this file except in compliance with rem the License. You may obtain a copy of the License at rem rem http://www.apache.org/licenses/LICENSE-2.0 rem rem Unless required by applicable law or agreed to in writing, software rem distributed under the License is distributed on an "AS IS" BASIS, rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License.
rem --------------------------------------------------------------------------- rem NT Service Install/Uninstall script rem rem Usage: service.bat install/remove [service_name [--rename]] [--user username] rem rem Options rem install Install the service using default settings. rem remove Remove the service from the system. rem rem service_name (optional) The name to use for the service. If not specified, rem Tomcat@VERSION_MAJOR@ is used as the service name. rem rem --rename (optional) Rename tomcat@VERSION_MAJOR@.exe and tomcat@VERSION_MAJOR@w.exe to match rem the non-default service name. rem rem username (optional) The name of the OS user to use to install/remove rem the service (not the name of the OS user the rem service will run as). If not specified, the current rem user is used. rem ---------------------------------------------------------------------------
setlocal
set"SELF=%~dp0%service.bat"
set DEFAULT_SERVICE_NAME=Tomcat@VERSION_MAJOR@ set SERVICE_NAME=%DEFAULT_SERVICE_NAME%
rem Guess CATALINA_HOME if not defined ifnot"%CATALINA_HOME%" == ""goto gotHome set"CATALINA_HOME=%cd%" ifexist"%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"goto gotHome ifexist"%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"goto gotHome rem CD to the upper dir cd .. set"CATALINA_HOME=%cd%"
:gotHome ifexist"%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" ( set"EXECUTABLE=%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" goto okHome
) ifexist"%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" ( set"EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" goto okHome
) if"%DEFAULT_SERVICE_NAME%"== "%SERVICE_NAME%" ( echo The file %DEFAULT_SERVICE_NAME%.exe was not found...
) else ( echo Neither the %DEFAULT_SERVICE_NAME%.exe file nor the %SERVICE_NAME%.exe file was found...
) echo Either the CATALINA_HOME environment variable is notdefined correctly or echo the incorrect service name has been used. echo Both the CATALINA_HOME environment variable and the correct service name echo are required to run this program. exit /b 1
:okHome cd"%CURRENT_DIR%"
rem Make sure prerequisite environment variables are set ifnot"%JRE_HOME%" == ""goto gotJreHome ifnot"%JAVA_HOME%" == ""goto gotJavaHome echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined echo Service will try to guess them from the registry. goto okJava
:gotJavaHome rem No JRE given, check if JAVA_HOME is usable as JRE_HOME ifnotexist"%JAVA_HOME%\bin\java.exe"goto noJavaHomeAsJre rem Use JAVA_HOME as JRE_HOME set"JRE_HOME=%JAVA_HOME%" goto okJava
:noJavaHomeAsJre echo The JAVA_HOME environment variable is notdefined correctly. echo JAVA_HOME=%JAVA_HOME% echo NB: JAVA_HOME should point to a JDK not a JRE. exit /b 1
:gotJreHome rem Check if we have a usable JRE ifnotexist"%JRE_HOME%\bin\java.exe"goto noJreHome goto okJava
:noJreHome rem Needed at least a JRE echo The JRE_HOME environment variable is notdefined correctly echo JRE_HOME=%JRE_HOME% echo This environment variable is needed to run this program exit /b 1
:gotBase rem Process the requested command if /i %SERVICE_CMD% == install goto doInstall if /i %SERVICE_CMD% == remove goto doRemove if /i %SERVICE_CMD% == uninstall goto doRemove echo Unknown parameter "%SERVICE_CMD%"
:displayUsage echo. echo Usage: service.bat install/remove [service_name [--rename]] [--user username] exit /b 1
:doRemove rem Remove the service echoRemoving the service '%SERVICE_NAME%' ... echo Using CATALINA_BASE: "%CATALINA_BASE%"
"%EXECUTABLE%" //DS//%SERVICE_NAME% ^
--LogPath "%CATALINA_BASE%\logs" ifnoterrorlevel 1 gotoremoved echo Failed removing '%SERVICE_NAME%' service exit /b 1
:removed echo The service '%SERVICE_NAME%' has been removed ifexist"%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
rename "%SERVICE_NAME%.exe""%DEFAULT_SERVICE_NAME%.exe"
rename "%SERVICE_NAME%w.exe""%DEFAULT_SERVICE_NAME%w.exe"
) exit /b 0
:doInstall rem Install the service echo Installing the service '%SERVICE_NAME%' ... echo Using CATALINA_HOME: "%CATALINA_HOME%" echo Using CATALINA_BASE: "%CATALINA_BASE%" echo Using JRE_HOME: "%JRE_HOME%"
rem Try to use the server jvm set"JVM=%JRE_HOME%\bin\server\jvm.dll" ifexist"%JVM%"goto foundJvm rem Try to use the client jvm set"JVM=%JRE_HOME%\bin\client\jvm.dll" ifexist"%JVM%"goto foundJvm echo Warning: Neither 'server' nor 'client' jvm.dll was found at JRE_HOME. set JVM=auto
:foundJvm echo Using JVM: "%JVM%"
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.