读书人

透过javaservice 将tomcat制作为系统服

发布时间: 2012-09-07 10:38:15 作者: rapoo

通过javaservice 将tomcat制作为系统服务

1.到http://javaservice.objectweb.org下载JavaService-2.0.10.

2.下载后,会在解压包中看到InstallTomcat.bat.

3.修改InstallTomcat.bat中的内容:

@echo offrem * JavaService installation script for Tomcat Application Serverrem *rem * JavaService - Windows NT Service Daemon for Java applicationsrem * Copyright (C) 2006 Multiplan Consultants Ltd. LGPL Licensing appliesrem * Information about the JavaService software is available at the ObjectWebrem * web site. Refer to http://javaservice.objectweb.org for more details.SETLOCALrem verify that the JavaService exe file is availableif not exist "JavaService.exe" goto no_jsexerem check that Tomcat version parameter is specified and recognisedif "%1" == "" goto no_versif "%1" == "4" SET TC_VERS=4if "%1" == "32" SET TC_VERS=32if "%1" == "31" SET TC_VERS=31if "%TC_VERS%" == "" goto no_versrem check that Java is installed and parameter is suppliedif "%2" == "" goto no_javaSET JAVA_HOME=%2if not exist "%JAVA_HOME%\jre" goto no_javarem check for any of server, hotspot or client Java run-timesSET jvmdll=%JAVA_HOME%\jre\bin\server\jvm.dllif not exist "%jvmdll%" SET jvmdll=%JAVA_HOME%\jre\bin\hotspot\jvm.dllif not exist "%jvmdll%" SET jvmdll=%JAVA_HOME%\jre\bin\client\jvm.dllif not exist "%jvmdll%" goto no_javaSET toolsjar=%JAVA_HOME%\lib\tools.jarif not exist "%toolsjar%" goto no_javarem check that Tomcat exists and parameter is specifiedif "%3" == "" goto no_tomcatSET TC_HOME=%3SET TC_BIN=%3\binif not exist "%TC_BIN%" goto no_tomcatrem add by zxj startrem check CPS_HOMEif "%5" == "" goto no_cpsset CPS_HOME=%5SET CPS_BIN=%5\binif not exist "%CPS_BIN%" goto no_cpsset CATALINA_OPTS= -verbose:gc -Xms256M -Xmx512M -DEMY_HOME="%CPS_HOME%" -Djava.library.path="%CPS_HOME%/lib/win32" -Dcom.emy.cps.fts.build.Optimize=falserem add by zxj endrem set up version-specific values for Tomcat installgoto tcv%TC_VERS%:tcv4SET TC_JARS=%TC_BIN%\bootstrap.jar;%TC_BIN%\servlet.jarSET TC_DEF=-Dcatalina.home=%TC_HOME%SET TC_START=org.apache.catalina.startup.Bootstrap -params startSET TC_STOP=org.apache.catalina.startup.Bootstrap -params stopgoto versok:tcv32SET TC_LIB=%TC_HOME%\libif not exist "%TC_LIB%" goto no_tomcatSET TC_XML=%TC_HOME%\conf\server.xmlif not exist "%TC_XML%" goto no_tomcatSET TC_JARS=%TC_LIB%\webserver.jar;%TC_LIB%\jasper.jar;%TC_LIB%\jaxp.jar;%TC_LIB%\parser.jar;%TC_LIB%\ant.jar;%TC_LIB%\servlet.jarSET TC_DEF=-Dtomcat.home=%TC_HOME%SET TC_START=org.apache.tomcat.startup.Tomcat -params -config %TC_XML%SET TC_STOP=org.apache.tomcat.startup.Tomcat -params -stop -config %TC_XML%goto versok:tcv31SET TC_LIB=%TC_HOME%\libif not exist "%TC_LIB%" goto no_tomcatSET TC_JARS=%TC_LIB%\webserver.jar;%TC_LIB%\jasper.jar;%TC_LIB%\xml.jar;%TC_LIB%\servlet.jarSET TC_DEF=-Dtomcat.home=%TC_HOME%SET TC_START=org.apache.tomcat.startup.Tomcat -params -startSET TC_STOP=org.apache.tomcat.startup.Tomcat -params -stopgoto versok:versokrem see if optional service mode parameter has been specifiedSET svcmode=if "%4" == "-manual" SET svcmode=-manualif "%4" == "-auto" SET svcmode=-autorem parameters and files seem ok, go ahead with the service installation@echo .rem Copy executable to get informative process image nameSET tcexe=%TC_BIN%\TomcatService.execopy JavaService.exe "%tcexe%" > nul%tcexe% -install Tomcat "%jvmdll%" %CATALINA_OPTS% -Djava.class.path="%TC_JARS%;%toolsjar%" %TC_DEF% -start %TC_START% -stop %TC_STOP% -out "%TC_HOME%\logs\stdout.log" -err "%TC_HOME%\logs\stderr.log" %svcmode%if ERRORLEVEL 1 goto js_errorgoto end:no_jsexe@echo . JavaService executable file not found, installation script cannot be rungoto error_exit:no_java@echo . This install script requires the parameter to specify Java location@echo . The Java run-time files tools.jar and jvm.dll must exist under that locationgoto error_exit:no_vers@echo . This install script requires the parameter to specify Tomcat version (4/32/31)goto error_exit:no_tomcat@echo . This install script requires thecparameter to specify Tomcat location@echo . The Tomcat server files must exist in the bin sub-directory at that locationgoto error_exit:no_cps@echo . This install script requires thecparameter to specify CPS_HOME locationgoto error_exit:js_error@echo . JavaService indicated an error in attempting to install the servicegoto error_exit:error_exit@echo .@echo . Failed to install Tomcat as a system service@echo .@echo . Command format:@echo .@echo .  %~n0 tomcat_version jdk_home tomcat_home [-auto / -manual] CPS_HOME@echo .@echo . Where:@echo . tomcatversion is 4, 32 or 31 (used to determine classpath, etc)@echo .  -auto (default) or -manual flag can specify startup mode for the service@echo .@echo . Example:@echo .  %~n0 4 c:\progra~1\jdk c:\progra~1\tomcat -auto CPS_HOME:endENDLOCAL@echo .@pause

?4.运行InstallTomcat.bat

?? InstallTomcat? 4? c:\progra~1\Java\jdk1.6.0_07? D:/tomcat4 -auto? D:\test

????? 参数说明:

    第一为tomcat的版本第二为java_home 目录,第三为tomcat4主目录,第四不需要修改,表示自动启动,第五表示CPS_HOME目录.

注:这里的CPS_HOME为我们自己的应用系统.需要在作为参数传递.读者可以根据自身实际需求决定是否使用.

? 5.运行完毕后,若正常会有安装成功的提示.

? 6.可以使用JavaService.exe uninstall 服务名,将已经安装过的服务反安装.

?

读书人网 >软件架构设计

热点推荐