把java程序作为windows服务运行

参考:

https://www.jianshu.com/p/fc9e4ea61e13

https://blog.csdn.net/qq_28566071/article/details/80882503

spring官方推荐使用winsw来将springboot项目作为服务运行,参考https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/htmlsingle/#deployment-windows

1.把java程序打包为jar包

2.下载winsw

winsw是一款可将可执行程序安装成Windows Service的开源工具,github:https://github.com/kohsuke/winsw/releases

下载文件:

需要将winsw执行程序跟xml改成同样的名字:

修改spider-1.0.xml文件内容

<configuration>
    <id>SpiderService</id> 
    <name>SpiderService</name>
    <description>This is Spider service.</description>
    <executable>java</executable> 
    <arguments>-jar spider-1.0.jar</arguments>
    <!-- 开机启动 -->
    <startmode>Automatic</startmode>
    <!-- 日志配置 -->
    <logpath>logs/service</logpath>
    <logmode>rotate</logmode>
</configuration>

配置完成后,命令行进入winsw所在的文件夹,执行“spider-1.0.exe install”,就注册服务了。

如果不再需要这个服务,使用spider-1.0.exe uninstall即可卸载服务。start启动和stop关闭服务

 

转载于:https://www.cnblogs.com/grasp/p/10214347.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值