把java程序jar包作为windows服务运行,开机自启
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
下载文件:

将该程序改名为wpisApp.exe
新建txt文件,内容为:
<configuration>
<id>WpisAppService</id>
<name>WpisAppService</name>
<description>This is wpisApp service.</description>
<executable>java</executable>
<!-- 管理系统软件路径 -->
<arguments>-jar G:\wpis_app.jar</arguments>
<!-- 开机启动 -->
<startmode>Automatic</startmode>
<!-- 日志配置 -->
<logpath>logs/service</logpath>
<logmode>rotate</logmode>
</configuration>
更改该txt文件名称为wpisApp.xml
3.启动服务
配置完成后,命令行进入winsw所在的文件夹,执行“wpisApp.exe install”,就注册服务了。
如果不再需要这个服务,使用wpisApp.exe uninstall即可卸载服务。start启动和stop关闭服务
文章目录
关闭
共有 0 条评论