在windows系统中tomcat服务的注册和删除,可以运用%TOMCAT_HOME%\bin\service.bat 来完成。
注意:目前免安装版的发布已经区分平台了(Tomcat6.0.24开始和 Tomcat7),需要下载windows平台对应的压缩包,否则在bin目录下没有:service.bat、tomcatX.exe、tomcatXw.exe 等文件。
注册服务:
1 |
>service.bat install |
删除服务:
1 |
service.bat remove |
也可以通过bin\tomcat6.exe 来对服务的注册和删除:
tomcat6w.exe的命令可选参数:
//ES// | Edit service configuration | This is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe |
---|---|---|
//MS// | Monitor service | Put the icon in the system try |
Command line arguments:
//TS// | Run the service as console application | This is the default operation. It is called if the no option is provided. The ServiceName is the name of the executable without exe suffix, meaning Tomcat6 |
---|---|---|
//RS// | Run the service | Called only from ServiceManager |
//SS// | Stop the service | |
//US// | Update service parameters | |
//IS// | Install service | |
//DS// | Delete service | Stops the service if running |
Command line parameters:
ParameterName | Default | Description |
---|---|---|
–Description | Service name description (maximum 1024 characters) | |
–DisplayName | ServiceName | Service display name |
–Install | procrun.exe //RS//ServiceName | Install image |
–Startup | manual | Service startup mode can be either auto or manual |
–DependsOn | List of services that this service depend on. Dependent services are separated using either # or ; characters | |
–Environment | List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters | |
–User | User account used for running executable. It is used only for StartMode java or exe and enables running applications as service under account without LogonAsService privilege. | |
–Password | Password for user account set by –User parameter | |
–JavaHome | JAVA_HOME | Set a different JAVA_HOME than defined by JAVA_HOME environment variable |
–Jvm | auto | Use either auto or specify the full path to the jvm.dll. You can use the environment variable expansion here. |
–JvmOptions | -Xrs | List of options in the form of -D or -X that will be passed to the JVM. The options are separated using either # or ; characters. |
–Classpath | Set the Java classpath | |
–JvmMs | Initial memory pool size in MB | |
–JvmMx | Maximum memory pool size in MB | |
–JvmSs | Thread stack size in KB | |
–StartImage | Executable that will be run. | |
–StartPath | Working path for the start image executable. | |
–StartClass | Class that will be used for startup. | |
–StartParams | List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character. | |
–StartMethod | Main | Method name if differs then main |
–StartMode | executable | Can one of jvm java or exe |
–StopImage | Executable that will be run on Stop service signal. | |
–StopPath | Working path for the stop image executable. | |
–StopClass | Class that will be used on Stop service signal. | |
–StopParams | List of parameters that will be passed to either StopImage or StopClass. Parameters are separated using either # or ; character. | |
–StopMethod | Main | Method name if differs then main |
–StopMode | executable | Can one of jvm java or exe |
–StopTimeout | No Timeout | Defines the timeout in seconds that procrun waits for service to exit gracefully. |
–LogPath | working path | Defines the path for logging |
–LogPrefix | jakarta_service | Defines the service log filename |
–LogLevel | INFO | Defines the logging level and can be either error, info, warn or debug |
–StdOutput | Redirected stdout filename | |
–StdError | Redirected stderr filename |
注册名称为’Tomcat6’的服务:
1 2 3 4 5 6 |
Install the service named 'Tomcat6' C:\> tomcat6 //IS//Tomcat6 --DisplayName="Apache Tomcat 6" \ C:\> --Install="C:\Program Files\Tomcat\bin\tomcat6.exe" --Jvm=auto \ C:\> --StartMode=jvm --StopMode=jvm \ C:\> --StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start \ C:\> --StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop |
更新名称为’Tomcat6’的服务信息
1 2 |
C:\> tomcat6 //US//Tomcat6 --Description="Apache Tomcat Server - http://tomcat.apache.org/ " \ C:\> --Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar |
移除名称叫’Tomcat6‘的服务
1 |
C:\> tomcat6 //DS//Tomcat6 |
详细见官网:http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html
service.bat 的代码 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
@echo off if "%OS%" == "Windows_NT" setlocal rem --------------------------------------------------------------------------- rem NT Service Install/Uninstall script rem rem Options rem install Install the service using Tomcat5 as service name. rem Service is installed using default settings. rem remove Remove the service from the System. rem rem name (optional) If the second argument is present it is considered rem to be new service name rem rem $Id: service.bat 467182 2006-10-23 23:47:06Z markt $ rem --------------------------------------------------------------------------- rem Guess CATALINA_HOME if not defined set CURRENT_DIR=%cd% if not "%CATALINA_HOME%" == "" goto gotHome set CATALINA_HOME=%cd% if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHome rem CD to the upper dir cd .. set CATALINA_HOME=%cd% :gotHome if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHome echo 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 program goto end rem Make sure prerequisite environment variables are set if not "%JAVA_HOME%" == "" goto okHome echo The JAVA_HOME environment variable is not defined echo This environment variable is needed to run this program goto end :okHome if not "%CATALINA_BASE%" == "" goto gotBase set CATALINA_BASE=%CATALINA_HOME% :gotBase set EXECUTABLE=%CATALINA_HOME%\bin\tomcat6.exe rem Set default Service name set SERVICE_NAME=Tomcat6 set PR_DISPLAYNAME=Apache Tomcat if "%1" == "" goto displayUsage if "%2" == "" goto setServiceName set SERVICE_NAME=%2 set PR_DISPLAYNAME=Apache Tomcat %2 :setServiceName if %1 == install goto doInstall if %1 == remove goto doRemove if %1 == uninstall goto doRemove echo Unknown parameter "%1" :displayUsage echo. 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 removed goto end :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 JAVA_HOME: %JAVA_HOME% rem Use the environment variables as an example rem Each command line option is prefixed with PR_ set PR_DESCRIPTION=Apache Tomcat Server - http://jakarta.apache.org/tomcat set PR_INSTALL=%EXECUTABLE% set PR_LOGPATH=%CATALINA_BASE%\logs set PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar rem Set the server jvm from JAVA_HOME set PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll if exist "%PR_JVM%" goto foundJvm rem Set the client jvm from JAVA_HOME set PR_JVM=%JAVA_HOME%\jre\bin\client\jvm.dll if exist "%PR_JVM%" goto foundJvm set PR_JVM=auto :foundJvm echo Using JVM: %PR_JVM% "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop if not errorlevel 1 goto installed echo Failed installing '%SERVICE_NAME%' service goto end :installed rem 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 jvm rem More extra parameters set PR_LOGPATH=%CATALINA_BASE%\logs set PR_STDOUTPUT=auto set PR_STDERROR=auto "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp" --JvmMs 128 --JvmMx 256 echo The service '%SERVICE_NAME%' has been installed. :end cd %CURRENT_DIR% |
原创文章,转载请注明: 转载自micmiu – 软件开发+生活点滴[ http://www.micmiu.com/ ]
本文链接地址: http://www.micmiu.com/enterprise-app/server/tomcat-windows-service/
0 条评论。