使用Java Service Wrapper工具制作
1.windows32位下载地址
https://sourceforge.net/projects/wrapper/files/
2.windows64位下载地址
https://www.krenger.ch/blog/java-service-wrapper-3-5-14-for-windows-x64/
步骤:
1.在本地磁盘新建一个文件夹例如weight_service,里面建立bin、conf、logs、lib文件夹
2.复制文件,下载好的文件目录以wrapper为例
将wrapper/bin目录里wrapper.exe
将wrapper/src/bin目录里App.bat.in
将wrapper/src/bin目录里InstallApp-NT.bat.in
将wrapper/src/bin目录里UninstallApp-NT.bat.in
统一拷贝至weight_service/bin目录里,并去掉后缀名in。
3.复制配置文件
将wrapper/src/conf目录wrapper.conf.in拷贝至weight_service/conf目录里去掉后缀名in
4.复制jar包
将wrapper/lib/目录里面的wrapper.jar和wrapper.dll拷贝至weight_service/lib目录里面,并且把自己项目的jar包也复制过来
5.修改配置文件 weight_serverconfwrapper.conf
(1)设置java命令(要安装jdk,配置jdk环境变量)
# Locate the java binary on the system PATH:
wrapper.java.command=java
(2)设置jdk目录
# Specify a specific java binary:
set.JAVA_HOME=%JAVA_HOME%/lib
(3)jar包配置
# 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/java-testDemo-1.0-SNAPSHOT.jar
wrapper.java.classpath.3=../lib/.
(4)java运行目录
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
(5)启动jar包后面可配置参数(参数 从1开始有序,参数前面都加上 -D)
# Java Additional Parameters
wrapper.java.additional.1=-Dserver.port=8443
wrapper.java.additional.2=-Dserver.address=test.com
wrapper.java.additional.3=-Dserver.ssl.key-store=classpath:server.p12
wrapper.java.additional.4=-Dserver.ssl.key-store-password=123456
wrapper.java.additional.5=-Dserver.ssl.keyStoreType=PKCS12
wrapper.java.additional.6=-Dserver.ssl.keyAlias=1
wrapper.java.additional.7=-Dtool.portName=COM1
wrapper.java.additional.8=-Dtool.baudrate=9600
wrapper.java.additional.9=-Dtool.timeout=2000
wrapper.java.additional.10=-Dtool.databyte=8
wrapper.java.additional.11=-Dtool.stopbyte=1
wrapper.java.additional.12=-Dtool.parity=0
wrapper.java.additional.13=-Dtool.flowcontrol=0
(6)设置启动方式(如果是org.tanukisoftware.wrapper.WrapperSimpleApp就不改)
# http://wrapper.tanukisoftware.com/doc/english/integrate.html
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
(7)启动主函数main入口
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=com.test.tool.App
(8)设置服务
# Name of the service
wrapper.name=server
(9)设置服务显示名称
# Display name of the service
wrapper.displayname=weightAppService
(10)设置服务描述
# Description of the service
wrapper.description=获取电子秤的重量
6.配置完成后,进入weight_serverin,按住 shift 点击鼠标右键,在此处打开命令窗口,输入 App.bat启动
7.进入weight_serverin点击InstallApp-NT.bat进行安装服务,在cmd中输入services.msc就可以看到制作的服务了,右击属性,启动类型改为自动就是开机自启
参考文章:
http://blog.csdn.net/sunny_sailor/article/details/7403025
http://www.2cto.com/kf/201312/263752.html
https://wrapper.tanukisoftware.com/doc/english/integrate-start-stop-win.html#parameter