火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

部署 JBoss 4.0.x 为 WindowsNT 系统服务

Posted on 2006-11-17 11:01  剑廿三  阅读(1447)  评论(0编辑  收藏  举报
1. 到 ObjectWeb 下载 JavaService.exe

主页:http://javaservice.objectweb.org/
下载:http://forge.objectweb.org/project/showfiles.php?group_id=137

2. 设定环境变量 JAVA_HOME  和 JBOSS_HOME

3. 拷贝 JBossService.exe 到 %JBOSS_HOME%\bin 目录下

4. 在 %JBOSS_HOME\bin% 目录下新建批处理文件 service.bat ,内容如下:

@echo off

rem * Register JBoss Application Server as WinNT Service
rem
 * Batch file written by Stephen Cat, Guangzhou, P.R.China on Nov. 17th, 2006.
rem
 *
rem
 * JavaService - Windows NT Service Daemon for Java applications
rem
 * Copyright (C) 2006 Multiplan Consultants Ltd. LGPL Licensing applies
rem
 * Information about the JavaService software is available at the ObjectWeb
rem
 * web site. Refer to http://javaservice.objectweb.org for more details.

SETLOCAL

SET SVCNAME=iTV JBoss 4.0.5
SET EXECNAME=JBossService.exe
SET MAXMEMORY=256
SET MINMEMORY=128

@
if "%1" == "install"   goto cmdInstall
@
if "%1" == "uninstall" goto cmdUninstall
echo Usage: service install
^|uninstall
goto end



:cmdInstall
rem check that Java is installed and environment variable set up
if "%JAVA_HOME%" == "" goto no_java
if not exist "%JAVA_HOME%\jre" goto no_java

rem check for any of server or client Java run-times
SET jvmdll=%JAVA_HOME%\jre\bin\server\jvm.dll
if not exist "%jvmdll%" SET jvmdll=%JAVA_HOME%\jre\bin\client\jvm.dll
if not exist "%jvmdll%" goto no_java
SET toolsjar=%JAVA_HOME%\lib\tools.jar
if not exist "%toolsjar%" goto no_java

set JAVA=%JAVA_HOME%\bin\java


rem check that JBoss exists and environment variable is set up
if "%JBOSS_HOME%" == "" goto no_jboss
if not exist "%JBOSS_HOME%\bin" goto no_jboss
SET jbossjar=%JBOSS_HOME%\bin\run.jar
if not exist "%jbossjar%" goto no_jboss

rem verify that the JavaService exe file is available
if not exist "%JBOSS_HOME%\bin\%EXECNAME%" goto no_jsexe

rem parameters and files seem ok, go ahead with the service installation

@echo .

SET jbossexe=%JBOSS_HOME%\bin\%EXECNAME%
set PROGNAME=run.bat

rem Include the JDK javac compiler for JSP pages. The default is for a Sun JDK
rem
 compatible distribution to which JAVA_HOME points

rem If JBOSS_CLASSPATH is empty, don't include it, as this will 
rem
 result in including the local directory, which makes error tracking
rem
 harder.
if "%JBOSS_CLASSPATH%" == "" (
    
set JBOSS_CLASSPATH=%toolsjar%;%jbossjar%
else (
    
set JBOSS_CLASSPATH=%JBOSS_CLASSPATH%;%toolsjar%;%jbossjar%
)

rem JVM memory allocation pool parameters. Modify as appropriate.
set JAVA_OPTS=%JAVA_OPTS% -Xms%MINMEMORY%m -Xmx%MAXMEMORY%m

rem With Sun JVMs reduce the RMI GCs to once per hour
set JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.
rem
 set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%

rem Setup the java endorsed dirs
set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed


"%jbossexe%" -install "%SVCNAME%" "%jvmdll%" -Djava.class.path="%JBOSS_CLASSPATH%" %JAVA_OPTS% -start org.jboss.Main -stop org.jboss.Main -method systemExit -out "%JBOSS_HOME%\bin\stdout.log" -err "%JBOSS_HOME%\bin\stderr.log" -current "%JBOSS_HOME%\bin" -auto -overwrite

if ERRORLEVEL 1 goto js_error

goto end

:cmdUninstall

rem check that JBoss exists and environment variable is set up
if "%JBOSS_HOME%" == "" goto no_jboss
if not exist "%JBOSS_HOME%\bin" goto no_jboss
SET jbossjar=%JBOSS_HOME%\bin\run.jar
if not exist "%jbossjar%" goto no_jboss

rem verify that the JavaService exe file is available
if not exist "%JBOSS_HOME%\bin\%EXECNAME%" goto no_jsexe

rem parameters and files seem ok, go ahead with the service installation

SET jbossexe=%JBOSS_HOME%\bin\%EXECNAME%

"%jbossexe%" -uninstall "%SVCNAME%"
goto end


:no_jsexe
@echo . %JBOSS_HOME%
\bin\%EXECNAME% not found, NT service installation failure.
goto error_exit

:no_java
@echo . JBossService requires the JAVA_HOME environment variable
@echo . The Java run
-time files tools.jar and jvm.dll must exist under that location
goto error_exit

:no_jboss
@echo . JBossService requires the JBOSS_HOME environment variable
@echo . The JBoss Application Server must exist in the bin 
sub-directory at that location
goto error_exit

:js_error
@echo . JBossService indicated an 
error in attempting to install the service
goto error_exit

:error_exit

@echo .
@echo . Failed 
to install JBoss as a system service
@echo .
@echo . Usage:
@echo .
@echo .  %~n0 install
^|uninstall


:
end
ENDLOCAL
@echo .
@pause

5. 修改批处理文件中 SET SVCNAME=xxx 的地方,填写要注册的服务名称。

6. 执行 service install 注册服务

7. 打开『管理工具-> 服务』启动注册成功的服务

8. 执行 service uninstall 卸载服务(卸载前要先停止服务)