众妙之门

业精于勤,荒于嬉;行成于思,毁于随

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

参考:

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关闭服务

 

posted on 2019-01-03 15:17  xuanm  阅读(6827)  评论(1编辑  收藏  举报