@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements. See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License. You may obtain a copy of the License atremrem remrem Unless required by applicable law or agreed to in writing, softwarerem 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 andrem limitations under the License.if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------rem NT Service Install/Uninstall scriptremrem Optionsrem install Install the service using Tomcat6 as service name.rem Service is installed using default settings.rem remove Remove the service from the System.remrem name (optional) If the second argument is present it is consideredrem to be new service name remrem $Id: service.bat 908749 2010-02-10 23:26:42Z markt $rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"rem if not "%CATALINA_HOME%" == "" goto gotHomerem set "CATALINA_HOME=%cd%"rem if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHomerem CD to the upper dircd ..set "CATALINA_HOME=%cd%":gotHomeif exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHomeecho The tomcat.exe was not found...echo The CATALINA_HOME environment variable is not defined correctly.echo This environment variable is needed to run this programgoto endrem Make sure prerequisite environment variables are setif not "%JAVA_HOME%" == "" goto okHomeecho The JAVA_HOME environment variable is not definedecho This environment variable is needed to run this programgoto end :okHomeif not "%CATALINA_BASE%" == "" goto gotBaseset "CATALINA_BASE=%CATALINA_HOME%":gotBase set "EXECUTABLE=%CATALINA_HOME%\bin\tomcat6.exe"rem Set default Service nameset SERVICE_NAME=eugenicsTomcat 服务名称set PR_DISPLAYNAME=eugenicsTomcat 服务显示名称if "%1" == "" goto displayUsage
if "%2" == "" goto setServiceNameset SERVICE_NAME=%2set PR_DISPLAYNAME=Apache Tomcat %2:setServiceNameif %1 == install goto doInstallif %1 == remove goto doRemoveif %1 == uninstall goto doRemoveecho Unknown parameter "%1":displayUsageecho.echo Usage: service.bat install/remove [service_name]goto end:doRemove
rem Remove the service"%EXECUTABLE%" //DS//%SERVICE_NAME%echo The service '%SERVICE_NAME%' has been removedgoto end:doInstall
cd..set "JAVA_HOME=%cd%\java\jdk1.6.0_21" 这句话是我添加的。用于指定环境变量。rem Install the serviceecho Installing the service '%SERVICE_NAME%' ...echo Using CATALINA_HOME: "%CATALINA_HOME%"echo Using CATALINA_BASE: "%CATALINA_BASE%"echo Using JAVA_HOME: "%JAVA_HOME%"rem Use the environment variables as an examplerem Each command line option is prefixed with PR_set PR_DESCRIPTION=Apache Tomcat 6.0.33 Server -
set "PR_INSTALL=%EXECUTABLE%"set "PR_LOGPATH=%CATALINA_BASE%\logs"set "PR_CLASSPATH=%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\bootstrap.jar"rem Set the server jvm from JAVA_HOMEset "PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll"if exist "%PR_JVM%" goto foundJvmrem Set the client jvm from JAVA_HOMEset "PR_JVM=%JAVA_HOME%\jre\bin\client\jvm.dll"if exist "%PR_JVM%" goto foundJvmset PR_JVM=auto:foundJvmecho Using JVM: "%PR_JVM%""%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stopif not errorlevel 1 goto installedecho Failed installing '%SERVICE_NAME%' servicegoto end:installedrem Clear the environment variables. They are not needed any more.set PR_DISPLAYNAME=set PR_DESCRIPTION=set PR_INSTALL=set PR_LOGPATH=set PR_CLASSPATH=set PR_JVM=rem Set extra parameters"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvmrem More extra parametersset "PR_LOGPATH=%CATALINA_BASE%\logs"set PR_STDOUTPUT=autoset PR_STDERROR=auto"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256echo The service '%SERVICE_NAME%' has been installed.sc config eugenicsTomcat start= auto 设置为开机自动启动服务sc start eugenicsTomcat 启动服务:end cd "%CURRENT_DIR%"