您的位置:首页 > 其它

JBOSS注册Windows系统服务

2014-08-09 00:33 302 查看
JBOSS注册Windows系统服务
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 JBoss, the OpenSource webOS

REM

REM Distributable under LGPL license.

REM See terms of license at gnu.org.

REM

REM-------------------------------------------------------------------------

REM JBoss Service Script for Windows

REM-------------------------------------------------------------------------

set PATH=e:\java\jdk1.7.0_01\bin;%PATH%;

@if not "%ECHO%" == ""echo %ECHO%

@if "%OS%" =="Windows_NT" setlocal

set DIRNAME=%CD%

rem Read an optional configuration file.

if "x%RUN_CONF%" == "x"(

set "RUN_CONF=%DIRNAME%\run.conf.bat"

)

if exist "%RUN_CONF%" (

call "%RUN_CONF%" %*

)

REM

REM VERSION, VERSION_MAJOR andVERSION_MINOR are populated

REM during the build with ant filter.

REM

if "x%SVCNAME%" == "x"(

set "SVCNAME=JBAS61SVC"

)

set SVCDISP=JBoss Application Server 6.1

set SVCDESC=JBoss Application Server 6.1.0Final/Platform: Windows %PROCESSOR_ARCHITECTURE%

set NOPAUSE=Y

REM Suppress killing service on logoffevent

if "x%JAVA_OPTS%" =="x" (

set"JAVA_OPTS=-Xrs"

) else (

set"JAVA_OPTS=-Xrs %JAVA_OPTS%"

)

REM Figure out the running mode

if /I "%1" =="install" goto cmdInstall

if /I "%1" =="uninstall" goto cmdUninstall

if /I "%1" =="start" goto cmdStart

if /I "%1" =="stop" goto cmdStop

if /I "%1" =="restart" goto cmdRestart

if /I "%1" =="signal" goto cmdSignal

echo Usage: serviceinstall^|uninstall^|start^|stop^|restart^|signal

goto cmdEnd

REM jbosssvc retun values

REM ERR_RET_USAGE 1

REM ERR_RET_VERSION 2

REM ERR_RET_INSTALL 3

REM ERR_RET_REMOVE 4

REM ERR_RET_PARAMS 5

REM ERR_RET_MODE 6

:errExplain

if %errorlevel% EQU 1 echo Invalid commandline parameters

if %errorlevel% EQU 2 echo Failedinstalling %SVCDISP%

if %errorlevel% EQU 4 echo Failed removing%SVCDISP%

if %errorlevel% EQU 6 echo Unknown servicemode for %SVCDISP%

goto cmdEnd

:cmdInstall

jbosssvc.exe -imwdc %SVCNAME%"%DIRNAME%" "%SVCDISP%" "%SVCDESC%" service.bat

if not errorlevel 0 goto errExplain

echo Service %SVCDISP% installed

goto cmdEnd

:cmdUninstall

jbosssvc.exe -u %SVCNAME%

if not errorlevel 0 goto errExplain

echo Service %SVCDISP% removed

goto cmdEnd

:cmdStart

REM Executed on service start

del .r.lock 2>&1 | findstr/C:"being used" > nul

if not errorlevel 1 (

echo Could not continue. Locking file already in use.

goto cmdEnd

)

echo Y > .r.lock

jbosssvc.exe -p 1 "Starting%SVCDISP%" > run.log

call run.bat -c web -b 0.0.0.0 < .r.lock >> run.log2>&1

jbosssvc.exe -p 1 "Shutdown %SVCDISP%service" >> run.log

del .r.lock

goto cmdEnd

:cmdStop

REM Executed on service stop

echo Y > .s.lock

jbosssvc.exe -p 1 "Shutting down%SVCDISP%" > shutdown.log

call shutdown -S < .s.lock >>shutdown.log 2>&1

jbosssvc.exe -p 1 "Shutdown %SVCDISP%service" >> shutdown.log

del .s.lock

goto cmdEnd

:cmdRestart

REM Executed manually from command line

REM Note: We can only stop and start

echo Y > .s.lock

jbosssvc.exe -p 1 "Shutting down%SVCDISP%" >> shutdown.log

call shutdown -S < .s.lock >>shutdown.log 2>&1

del .s.lock

:waitRun

REM Delete lock file

del .r.lock > nul 2>&1

REM Wait one second if lock file exist

jbosssvc.exe -s 1

if exist ".r.lock" goto waitRun

echo Y > .r.lock

jbosssvc.exe -p 1 "Restarting%SVCDISP%" >> run.log

call run.bat -c web -b 0.0.0.0 < .r.lock >> run.log2>&1

jbosssvc.exe -p 1 "Shutdown %SVCDISP%service" >> run.log

del .r.lock

goto cmdEnd

:cmdSignal

REM Send signal to the service.

REM Requires jbosssch.dll to be loaded inJVM

@if not ""%2"" =="""" goto execSignal

echo Missing signal parameter.

echo Usage: service signal [0...9]

goto cmdEnd

:execSignal

jbosssvc.exe -k%2 %SVCNAME%

goto cmdEnd

:cmdEnd

-------------------------------------------------------------------------------------------------------------------------------

7. 在cmd进入%JBOSS_HOME%\bin目录下,执行 service install 注册服务

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

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

文章来源:http://qtlkw.iteye.com/blog/588428

JavaService.exe 下载地址:http://pan.baidu.com/s/1jGuYfpO

service.bat 下载地址:http://pan.baidu.com/s/1i39ToRb
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: