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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM