使用WRAPPER制作JAVA程序为WINDOWS服务 留着看看

使用一个第三方的软件将java写的应用注册成为windows的服务。

比如说james,activeMQ,hsql db,MSQL等,注册成为了服务后,不用每天对着一个
CMD的DOS窗口,也不用每天启动了电脑后去启动这些程序,也是一件比较爽的事情。
用到的第三方的软件是java service wrapper,
1.下载
    下载地址是http://wrapper.tanukisoftware.org/doc/english/download.jsp我用的版本是3.3.1最新版本。
     找到Download by Platform中的
     32-bit OS Windows CPU x86 3.3.1 Professional
     32位的Windows 系统商业的版本为3.3.1
     下载http://wrapper.tanukisoftware.org/download/3.3.1/ wrapper-windows-x86-32 -3.3.1-pro.zip
     你也可以下载下面的File Type所有的开源代码和详细的文档
2、准备如下文件,复制到test目录,这些文件可以从下载包中找到:
wrapper. dll
wrapper.exe
wrapper.jar
3、编写wrapper.conf

另外wrapper.conf就要修改得多了,我把整个文件都列出来,一个一个看,wrapper.conf:
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application j2sdk所安装的路径,如果path中有d://tool/j2sdk/bin,那么只写个java就可以了
wrapper.java.command=java

# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details. 这个不用修改了
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1 从1开始,把hsqldb要用到的jar也要加入进去
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/hsqldb.jar

# Java Library Path (location of Wrapper. DLL  or libwrapper.so)
# 这个主要是加入那个wrapper. dll 吧,我理解的是
wrapper.java.library.path.1=../lib

# Java Additional Parameters 启动JVM的参数
#wrapper.java.additional.1=

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# Application parameters. Add parameters as needed starting from 1
# 第一个是启动hsqldb的主函数,从hsqldb的启动bat里面找到的,另外的就是启动参数了
wrapper.app.parameter.1=org.hsqldb.Server
wrapper.app.parameter.2=-database.0 sillycat
wrapper.app.parameter.3=-dbname.0 sillycat
wrapper.app.parameter.4=-port 9002

#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM

# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO

# Log file to use for wrapper output logging.
wrapper.logfile=../logs/wrapper.log

# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM

# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO

# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0

# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0

# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE

#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=Hsql DB

#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.


#window服务配置
wrapper.console.title=Hsql DB

# Name of the service 应用的名字
wrapper.ntservice.name=Hsql DB                                        服务名

# Display name of the service
wrapper.ntservice.displayname=Hsql DB                                 显示名称

# Description of the service
wrapper.ntservice.description=Hsql DB#                                描述

# Service dependencies. Add dependencies as needed starting from 1    依赖项
wrapper.ntservice.dependency.1=

# Mode in which the service is installed. AUTO_START or DEMAND_START 启动模式
wrapper.ntservice.starttype=AUTO_START

# Allow the service to interact with the desktop.    是否把服务程序放在桌面上
wrapper.ntservice.interactive=false

这个配置文件搞定了以后,就可以运行hsqldb.bat来测试一下,我们通过wrapper能不能正常启动
hsqldb,如果测试通过了。
那么就简单了,运行如下命令
wrapper.exe -i wrapper.conf -----装载WINDOWS服务
wrapper.exe -r wrapper.conf -----卸载WINDOWS服务

4、运行测试,安装服务

》测试运行是否正常
wrapper.exe -c wrapper.conf
》安装服务
wrapper.exe -i wrapper.conf
》卸载服务
wrapper.exe -r wrapper.conf
》启动
wrapper.exe -t wrapper.conf
》停止
wrapper.exe -p wrapper.conf



下面是我们服务器的wrappers.conf文件的详细文件

# Java Application完整路径
wrapper.java.command=java

wrapper.java.mainclass=org.esdimserver.server.WhileUDPServer

#定义程序运行的classpath
wrapper.java.classpath.1=Server.jar
wrapper.java.classpath.2=[jar file/path]

# Java Library Path (location of Wrapper. DLL  or libwrapper.so)
wrapper.java.library.path.1=.

# Java Additional Parameters
#wrapper.java.additional.1=

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# 运行的Main Class
wrapper.app.parameter.1=

wrapper.console.format=PM
wrapper.console.loglevel=INFO
wrapper.logfile=Beanskt.log
wrapper.logfile.format=LPTM
wrapper.logfile.loglevel=INFO

wrapper.logfile.maxsize=0
wrapper.logfile.maxfiles=0
wrapper.syslog.loglevel=NONE

#window服务配置
wrapper.console.title=Server_esd3
#服务名
wrapper.ntservice.name=Server_esd3

# 显示名称
wrapper.ntservice.displayname=Server_esd3 Service

# 描述
wrapper.ntservice.description=Server_esd3 Service

# 依赖项
wrapper.ntservice.dependency.1=

# 启动模式: AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START

# 是否交互.
wrapper.ntservice.interactive=false

你可能感兴趣的:(使用WRAPPER制作JAVA程序为WINDOWS服务 留着看看)