本文介绍基于 WinSW 将 Java 程序部署 为 Windows 自启动服务。
我们使用 Java -jar file.jar 将 Java 程序运行,起来,但是窗口关闭,服务就停止了。
WinSW 可以将 Windows 上的任何一个程序注册为服务,如果不需要,也可以方便的卸载服务。
https://github.com/kohsuke/winsw
1、下载 winsw 文件
下载 winsw-2.1.2-bin.exe 文件
http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/
最好修改下文件名称,本文修改为 winsw-ai-server
2、添加配置文件
根据 winsw 文件名,新建相同名称的 xml 文件
<service>
<id>phcj-ai-server</id>
<name>phcj-ai-server</name>
<description>系统 AI 后台服务</description>
<executable>java</executable>
<onfailure action="restart" delay="10 sec"/>
<arguments> -jar "D:\PHCJ\phcj-ai-server\target\phcj-ai-server-0.0.1-SNAPSHOT.jar"</arguments>
<log mode="roll-by-size">
<sizeThreshold>20480</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
</service>
3、安装并启动服务
注意以管理员身份运行
安装服务 ./winsw-ai-server.exe install
启动服务 net start phcj-ai-server
停止服务 net stop phcj-ai-server
卸载服务 ./winsw-ai-server.exe uninstall
参考资料:
1、winsw将可运行的jar文件做成后台服务 - qq_31451471的博客 - CSDN博客
https://blog.csdn.net/qq_31451471/article/details/79298665
2、用winsw让任何Windows程序都能运行为服务 - 简书
https://www.jianshu.com/p/fc9e4ea61e13
3、使用WinSW将SpringBoot程序安装成Windows自启动服务 - blvyoucan的专栏 - CSDN博客
https://blog.csdn.net/blvyoucan/article/details/81131234
4、Spring Boot项目生成jar包,并在windows服务器中注册成服务,开机启动 - LiveYourLife - 博客园
https://www.cnblogs.com/LiveYourLife/p/8681137.html
5、springboot解决第三方依赖jar包的问题 - 浅夏丶未央 - 博客园
https://www.cnblogs.com/xiaosiyuan/p/6894766.html
评论 (0)