和Java Service Wrapper一样,WinSW也可以将java的jar程序转为windows服务,而且:
- 配置文件更精简直观
- 运行更简便
- 免费开源!
1、下载:
可以直接在GitHub上下载:
https://github.com/kohsuke/winsw
鉴于墙的原因,并不是随时都能够在GitHub上下载,这里提供百度云链接:
链接:http://pan.baidu.com/s/1cxT2F0
密码:ewzm
2、使用步骤:
2.1、更改文件名
更改MyApp.xml和MyApp.exe文件名,改成什么不重要,重要的是两个文件的文件名要保持一致。
更改文件名后,将jar包拷到目录下:
2.2、更改MyApp.xml配置文件
<service>
<!--id、name、description为服务信息-->
<id>MyApp</id>
<name>MyApp</name>
<description>This is MyApp!!</description>
<!--executable标签和argument标签加起来相当于在控制台输入java -jar 当前目录/MyApp.jar-->
<executable>java</executable>
<arguments>-jar "%BASE%\MyApp.jar"</arguments>
<!--配置log模式-->
<logmode>rotate</logmode>
</service>
更多的XML配置信息可以在GitHub上查看:
https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md
2.3、运行
2.3.1、安装服务
以管理员模式打开控制台(如果不以管理员模式打开,可能报AssessDenied异常),然后输入命令:
MyApp.exe install
就可以将jar转为windows服务并注册。
然后在服务列表中启动服务即可。
2.3.2、卸载服务
输入命令:
MyApp.exe uninstall
即可将安装好的windows服务卸载。
2.3.3、其他命令
start
to start the service. The service must have already been installed.stop
to stop the service.restart
to restart the service. If the service is not currently running, this command acts likestart
.status
to check the current status of the service.