快捷搜索:

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

近来应用了一个第三方的软件将java写的利用注册成为windows的办事。

比如说james,activeMQ,hsql db等,注册成为了办事后,不用天天对着一个

CMD窗口,也不用天天启动了电脑后去启动这些法度榜样,也是一件对照爽的工作。

用到的第三方的软件是java service wrapper,下载地址是

http://wrapper.tanukisoftware.org/doc/english/integrate-simple-win.html

我用的版本是3.2.3最新版本。

在hsqldb里面的data目录原先有runServer.bat,启动了之后的数据库是sillycat

runServer.bat脚本是这样写的:

@java -classpath ../lib/hsqldb.jar org.hsqldb.Server -database.0 sillycat -dbname.0 sillycat -port 9002

那首先我们拷贝并且重命名

E:\book\wrapper\wrapper-windows-x86-32-3.2.3\src\bin\App.bat.in---D:\tool\hsqldb\data\Hsqldb.bat

E:\book\wrapper\wrapper-windows-x86-32-3.2.3\src\conf\wrapper.conf.in---D:\tool\hsqldb\data\wrapper.conf

E:\book\wrapper\wrapper-windows-x86-32-3.2.3\bin\wrapper.exe---D:\tool\hsqldb\data\wrapper.exe

E:\book\wrapper\wrapper-windows-x86-32-3.2.3\lib\wrapper.dll---D:\tool\hsqldb\lib\wrapper.dll

E:\book\wrapper\wrapper-windows-x86-32-3.2.3\lib\wrapper.jar---D:\tool\hsqldb\lib\wrapper.jar

此中hsqldb.bat是我们测试用的,wrapper.conf是设置设置设备摆设摆设文件,wrapper.exe,wrapper.dll,wrapper.jar都是必要的文件

,我们

可以在wrapper.conf中设置设置设备摆设摆设它的路径和名字的。

首先看hsqldb.bat,此中有行set _WRAPPER_CONF="%_REALPATH%\conf\wrapper.conf"

应为我们已经把脚本和设置设置设备摆设摆设放在了一个目录下面,以是要改动为:

set _WRAPPER_CONF="%_REALPATH%\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.

# 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办事

james邮件系统的D:\tool\james-2.3.1\bin下面就有wrapper.exe,只要把D:\tool\james-2.3.1\conf\wrapper.conf

拷贝过来运行敕令就可以了,不过james-2.3.1版本用的wrapper似乎不是最新版本的。有些不合。

activeMQ的D:\tool\apache-activemq-4.1.1\bin\win32下面也是筹备好了的,运行敕令就可以了。

您可能还会对下面的文章感兴趣: