vjame

优化代码是无止境的
随笔 - 65, 文章 - 9, 评论 - 26, 引用 - 0
数据加载中……

使用Java Service Wrapper工具把Java程序提升为Windows系统服务

 

在使用之前需下载Java Service Wrapper的发布包

http://sourceforge.net/project/showfiles.php?group_id=39428


下面简单介绍一下具体的使用步骤:

1.  将下载的Java Service Wrapper包解压到本地,目录为{WRAPPER_HOME}
2.  
服务应用程序名为MyServApp,在目录d:"MyServApp下建立binconflogslib目录;并把你的已有应用程序如NioBlockingServer.class拷贝到该目录下;
3.  
{WRAPPER_HOME}"src"bin"下的遗以下文件拷贝到MyServApp目录下,并重命名。
{WRAPPER_HOME}"bin"Wrapper.exe C:" MyServApp "bin"Wrapper.exe
à
 C:"
à{WRAPPER_HOME}"src"bin"App.bat.in MyServApp"bin"MyApp.bat
 C:"
à{WRAPPER_HOME}"src"bin"InstallApp-NT.bat.in MyServApp"bin"InstallMyApp-NT.bat
{WRAPPER_HOME}"src"bin"UninstallApp-NT.bat.in C:" MyServApp"bin"UninstallMyApp-NT.bat
à
4.  
{WRAPPER_HOME}"lib下的以下文件拷贝到C:" MyServApp "lib目录下
{WRAPPER_HOME}"lib"Wrapper.DLL
{WRAPPER_HOME}"lib"wrapper.jar
5.  
{WRAPPER_HOME}"src"conf"wrapper.conf.in拷贝到C:" MyServApp "conf目录下并命名为wrapper.conf;并修改wrapper.conf文件,在其中配置您的应用服务。
主要修改以下几项即可:
#
你的JVM位置:
wrapper.java.command=D:"Sun"j2sdk1.4.0_03"bin"java
#
运行参数:如:
wrapper.java.additional.1=-Dprogram.name=run.bat
#classpath

wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../bin/.
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS
此处决定了使用Java Service Wrapper的方式
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
#
你的Java应用类
wrapper.app.parameter.1= NonBlockingServer
#
服务名
wrapper.ntservice.name=NB

# Display name of the service
wrapper.ntservice.displayname=Nio Nonblocking Server
#
服务描述
wrapper.ntservice.description=Nio Nonblocking Server
其他的配置根据你的需要改变即可
6.  
对以上配置的MyApp.bat进行测试,运行MyApp.bat,就像在Console窗口下运行Tomcat一样;
7.  
对以上配置的服务进行测试,运行C:" MyServApp"bin"InstallMyApp-NT.bat将把你的应用(此处为NioBlockingServer)安装到Win32系统服务中了。
8.  
打开控制面板-管理程序-服务,看到Nio Nonblocking Server已经在系统服务中了,其他用法就与我们熟悉的Windows服务一样了。

 

JAVA程序部署为Windows Service需要修改的操作

1.JAVA程序所用到的Class拷到bin目录下;所有jar考到lib目录

2.修改config/wrapper.conf 文件

       1)修改JDK安装路径 :wrapper.java.command=C:"jdk1.5.0"bin"java

       2)修改classpath:wrapper.java.classpath.2=../bin/.

       3)修改要启动的JAVA:wrapper.app.parameter.1= HelloWorld

       4)修改服务名称:wrapper.ntservice.name=MyJavaService

       5)修改"服务"里显示的名称:wrapper.ntservice.displayname=MyJavaService

       6)服务说明:wrapper.ntservice.description=MyJavaService Test

bin/StartApp.bat    为控制台方式运行程序

bin/InstallApp-NT.bat  安装服务

bin/UninstallApp-NT.bat 删除服务

把项目中的接收程序提升为系统服务

config/wrapper.conf 文件

#********************************************************************

# Wrapper Properties

#********************************************************************

# Java Application

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

wrapper.java.classpath.1=../lib/wrapper.jar

wrapper.java.classpath.2=../lib/wrappertest.jar

wrapper.java.classpath.3=../bin/.

wrapper.java.classpath.4=../lib/jaxen-1.1-beta-7.jar

wrapper.java.classpath.5=../lib/tlclient.jar

wrapper.java.classpath.6=../lib/tlqadapter.jar

wrapper.java.classpath.7=../lib/tlqconf.jar

wrapper.java.classpath.8=../lib/TlqMng.jar

wrapper.java.classpath.9=../lib/weblogic.jar

wrapper.java.classpath.10=../lib/jms.jar

wrapper.java.classpath.11=../lib/log4j-1.2.8.jar

wrapper.java.classpath.12=../lib/swt.jar

wrapper.java.classpath.13=../lib/javax.jms.jar

wrapper.java.classpath.14=../lib/jaxrpc.jar

wrapper.java.classpath.15=../lib/commons-discovery-0.2.jar

wrapper.java.classpath.16=../lib/commons-logging-1.0.4.jar

wrapper.java.classpath.17=../lib/dom4j-1.6.1.jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)

wrapper.java.library.path.1=../lib

# Java Additional Parameters

#wrapper.java.additional.1= -Dprogram.name=StartApp.bat

# 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

wrapper.app.parameter.1= MainTest

#********************************************************************

# 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/log.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=MyJavaService

#********************************************************************

# 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.

# Name of the service

wrapper.ntservice.name=MyJavaService

# Display name of the service

wrapper.ntservice.displayname=MyJavaService

# Description of the service

wrapper.ntservice.description=MyJavaService Test

# 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

采用这种方式,即可简单有效的把我们的服务程序包装成为系统服务程序,并增强了日志功能,我们可以把MyServApp的几个文件做成模板,每次修改文件名,配置文件就可以了,还可以做成Eclipse的plugin,鼠标点点就把应用配成服务了。 

posted on 2009-01-12 10:46 lanjh 阅读(1337) 评论(1)  编辑  收藏 所属分类: Java App

评论

# re: 使用Java Service Wrapper工具把Java程序提升为Windows系统服务  回复  更多评论   

Hi, I googled from the WWW and found this article written by your own. What a surprise! Amazing! Brilliant!
2009-09-24 11:19 | GuoGuo(Heinvo Lee)

只有注册用户登录后才能发表评论。


网站导航: