Java Service Wrapper
Java Service Wrapper
将Java 应用程序部署成Windows系统服务Java Service Wrapper 1
Methods of Integrating with the Java Service Wrapper 2
Method 1 - WrapperSimpleApp Integration (Windows) 2
Export your program as a runnable jar 2
Modifying the "wrapper.conf" File 3
Initial Java Heap Size (in MB) 4
Maximum Java Heap Size (in MB) 4
Product Overview
The Java Service Wrapper enables a Java Application to be run as a Windows Service or UNIX Daemon. It also monitors the health of your Application and JVM.Please select the specific download for the platform and edition which meets your needs. All editions of the Wrapper can be downloaded freely. The Standard and Professional editions require that a valid license be present in the configuration file to run.
Editions
The Java Service Wrapper comes in three editions.
· Professional Edition - Includes all basic and advanced features.
· Standard Edition - Includes all basic and some advanced features.
· Community Edition - Includes all basic features.
Methods of Integrating with the Java Service Wrapper
There are currently four ways which a Java application can integrate with the Java Service Wrapper. Three of which will work out of the box without any additional coding.
The first step is to decide which of these four methods is best for your application. After a brief overview of each of the four options, we will go into detail how to integrate an application using each.
· Integration Method 1 (WrapperSimpleApp)
· Integration Method 2 (WrapperStartStopApp)
· Integration Method 3 (WrapperListener)
· Integration Method 4 (WrapperJarApp)
Method 1 - WrapperSimpleApp Integration (Windows)
建立新文件夹D:\MyService 并新建bin、lib、conf、logs四个子文件
Export your program as a runnable jar
将你的项目以runnable jar file(必须以此形式导出)的形式导出(命名为A.jar)。
Installing Wrapper Files
根据你的操作系统平台以及操作系统类型下载合适的Java Service Wrapper版本 ,链接地址:http://wrapper.tanukisoftware.com/doc/english/download.jsp ,解压到任意目录。
bin directory
拷贝Java Service Wrapper解压文件中src\bin目录下的App.bat.in、InstallApp-NT.bat.in、UninstallApp-NT.bat.in以及bin目录下的wrapper.exe到D:\MyService\bin目录下。
重命名App.bat.in、InstallApp-NT.bat.in、UninstallApp-NT.bat.in为App.bat、InstallApp-NT.bat、UninstallApp-NT.bat。
lib directory
拷贝Java Service Wrapper解压文件中lib目录下的wrapper.jar和wrapper.dll到D:\MyService\lib。
拷贝工程A.jar到D:\MyService\lib。
添加工程A依赖的第三方包到D:\MyService\lib。
conf directory
拷贝Java Service Wrapper解压文件中conf 目录下的wrapper.conf 到D:\MyService\conf。
logs directory
拷贝Java Service Wrapper解压文件中conf 目录下的wrapper 到D:\MyService\logs。
Modifying the "wrapper.conf" File
java executable
下载和安装java sdk,并设置环境变量(计算机-属性-高级系统设置-高级-环境变量):
在系统变量中设置:
变量名:JAVA_HOME
变量值:D:\Program Files\Java\jdk1.7.0_21
变量名:CLASSPATH
变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
wrapper.java.command=%JAVA_HOME%/bin/java
main class
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
classpath
wrapper.java.classpath.1=../lib/A.jar
wrapper.java.classpath.2=../lib/wrapper.jar
添加其他项目A 所需的第三方包
library path
wrapper.java.library.path.1=../lib
Additional Parameters
wrapper.java.additional.1=-Dprogram.name=App.bat
Initial Java Heap Size (in MB)
wrapper.java.initmemory=128
Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=512
application parameters
wrapper.app.parameter.1=B(the main class in A.jar)
Trying It Out
完成以上步骤后,即可点击bin\App.bat,若未出现错误提示,则表明配置成功。即可点击bin\InstallApp-NT.bat将java应用程序部署成Windows系统服务。可进入控制版面-管理工具-服务,查看系统服务部署成功与否,并启动该服务。UninstallApp-NT.bat用于卸载该服务。
附录:
另附一个java写的服务器工程(MapUpdateS)用于实践以及部署好Windows服务文件(MyService)。
使用前可修改MapUpdateS下mapupdates.class下的IP地址为你本机地址(0.0.0.0),然后导出jar文件MapUpdates.jar到MyService\lib目录.成功启动系统服务后,可在浏览器地址栏输入 0.0.0.0:8083以及http://0.0.0.0:8082/cache?wsdl查看服务是否正常工作。