使用Apache Commons Daemon 来实现Jetty7 以Windows 服务方式运行
2012-03-04 23:13
627 查看
本文将介绍如何使用 Apache Commons Daemon 来实现Jetty7 以Windows 服务方式运行,如果你使用的是 Jetty6 请直接查看 Jetty 的Win32Wrapper。
开始前你需要准备:
JDK1.5 以上,在这里选择适合你的版本。
Jetty7,如果你还没有请在这里下载。
已编译好的 Apache Commons Daemon Windows 版,可以在这里下载(支持32位与64位系统)。
准备完成后我们开始:
将 jetty7 解压到目录 D:\jetty7,目录可以根据你的需要进行修改。
解压 Apache Commons Daemon (当前版本是 commons-daemon-1.0.7-bin-windows.zip)到临时目录,如果是32位系统将其根目录下的 prunmgr.exe 与 prunsrv.exe 两个可执行文件拷贝到 D:\jetty7\bin 里面。Prunsrv 是一个服务应用可以让任何应用程序作为一个服务运行,不仅仅局限于 Java,Prunmgr 是一个图形界面程序,用来监控和配置 Prunsrv 的服务,更多详细信息请看这里。
创建脚本,进入文件夹 D:\jetty7\bin,使用记事本或其他文本编辑器创建文件 service.bat (在文章最后提供下载),其内容如下:
@echo off rem ---------------------------------------------------- rem Install/Uninstall Jetty7 NT Service rem www.originsoft.net ,jingwei@originsoft.net rem ---------------------------------------------------- rem set JAVA_HOME=D:\java\jdk\jdk16 set JETTY_PORT=8080 set JETTY_STOP_PORT=8087 rem -Xmx1024m -Xms256m set Xmx=1024 set Xms=256 set SERVICE_NAME=Jetty7 set CURRENT_DIR=%cd% cd.. set JETTY_HOME=%cd% set PRUNSRV_EXE=%JETTY_HOME%\bin\prunsrv.exe if "%1" == "" goto showUsage if %1 == install goto doInstall if %1 == uninstall goto doUninstall echo Unknown parameter "%1" :showUsage echo Usage: service.bat install/uninstall goto end :doInstall set PR_DISPLAYNAME=Jetty7 set PR_DESCRIPTION=Jetty7 Server - http://www.eclipse.org/jetty/ set PR_INSTALL=%PRUNSRV_EXE% set PR_LOGPATH=%JETTY_HOME%\logs set PR_STDOUTPUT=auto set PR_STDERROR=auto set PR_STARTMODE=jvm set PR_STOPMODE=jvm set PR_CLASSPATH=%JETTY_HOME%\start.jar set PR_STARTCLASS=org.eclipse.jetty.start.Main set PR_STOPCLASS=org.eclipse.jetty.start.Main 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% "%PRUNSRV_EXE%" //IS//%SERVICE_NAME% --StopParams=--stop --JvmOptions="-Djetty.port=%JETTY_PORT%;-Djetty.home=%JETTY_HOME%;-Djetty.logs=%PR_LOGPATH%;-DSTOP.PORT=%JETTY_STOP_PORT%;-DSTOP.KEY=jingwei" --JvmMs=%Xms% --JvmMx=%Xmx% if not errorlevel 1 goto installed echo Failed installing '%SERVICE_NAME%' service goto end :installed echo The service '%SERVICE_NAME%' has been installed. goto end :doUninstall "%PRUNSRV_EXE%" //DS//%SERVICE_NAME% echo The service '%SERVICE_NAME%' has been uninstalled. goto end :end cd %CURRENT_DIR%
注册服务,使用命令行( cmd.exe ),进入文件夹 D:\jetty7\bin ,执行命令:
1 | service.bat install |
启动服务,打开 Windows 服务管理器(services.msc),找到 Jetty7 并启动,正常启动后打开浏览器输入地址:http://localhost:8080,当出现 Jetty 的欢迎界面则说明服务安装成功。
卸载服务,同样使用命令行进入文件夹 D:\jetty7\bin ,执行命令:
1 | service.bat uninstall |
注意:
如果你使用 Windows7 系统,必须使用管理身份运行命令行,否则不能正常安装。
如果在同一系统中安装一个以上的服务,请将prunsrv.exe修改为不重复的名字(否则多个程序使用同一进程)并且需要修改Jetty的服务端口和关闭端口。
附件:
commons-daemon-1.0.7-bin-windows.zip
service.zip
相关文章推荐
- 使用apache daemon让java程序在unix系统上以服务方式运行
- 使用apache daemon让java程序在unix系统上以服务方式运行
- windows 使用sc命令将程序注册成服务 实现后台运行开机自启
- 使用apache daemon让java程序在unix系统上以服务方式运行
- CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动
- windows下面使用nssm设置新的服务实现开机自启等
- Windows下Nginx以服务的方式运行
- 使用Django REST Framework来快速实现API调用服务——上篇(运行环境和模型层)
- Windows下Nginx以服务的方式运行
- Windows下使用HAXM加速Android模拟器(以x86方式运行)
- Windows Service开发日志四(用程序设置服务的运行状态及启动方式)
- Windows多线程总结(4)-- 线程同步(使用互斥对象实现线程同步 只运行一个对象)
- Windows上运行Eclipse使用virtualbox搭建的Ubuntu的hadoop集群服务
- Confluence 6 Windows 中以服务方式自动重启修改运行服务的用户
- 在Windows上以服务方式运行 MSOPenTech/Redis
- 【转载】nginx for windows: 让nginx以服务的方式运行
- 基于SignalR实现B/S系统对windows服务运行状态的监测
- nginx/windows: 让nginx以服务的方式运行
- Redis启动多个实例,并以windows服务方式运行
- Confluence 6 Windows 中以服务方式自动重启修改运行服务的用户