部署 JBoss 4.0.x 为 WindowsNT 系统服务
1. 到 ObjectWeb 下载 JavaService.exe
2. 设定环境变量 JAVA_HOME 和 JBOSS_HOME
右键单击"我的电脑"--->选择"高级"选项卡--->点击"环境变量"--->在下面的"系统变量"中点击"新建"
--->在弹出的"新建系统变量"窗口中分别输入变量名: JBOSS_HOME 变量值:jboss目录 ---->确定
3. 拷贝 JavaService.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=JBoss 4.0.2
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 的地方,填写要注册的服务名称。如:SET SVCNAME=Jboss-4.0.2
6. 执行 service install 注册服务
进入到%JBOSS_HOME%/bin目录下,执行: service install JDK目录 jboss目录 server
注意:中间是空格.
7. 打开『管理工具-> 服务』启动注册成功的服务
8. 执行 service uninstall 卸载服务(卸载前要先停止服务)
执行:service uninstall JDK目录 jboss目录 server