将SpringBoot的Jar注册成Windows服务的实现方法
介绍
WinSW是一个通用的Windows服务包装器,可以将任何可执行文件(.exe,.bat等)包装成Windows服务。WinSW无需安装,仅需将winsw.exe和配置文件复制到指定目录即可。WinSW通过一个Xml配置文件来定义服务的行为,可以轻松地安装,卸载,启动和停止自定义Windows服务。
操作
WinSW的开源项目地址为:https://github.com/winsw/winsw
把SpringBoot项目打包成Jar之后,将引用到的jar一起放到WinSW.exe所在的目录下,可以把WinSW.exe自行修改为当前对应的服务名称,如MapEditorServer.exe,对应的XML文件也重命名为MapEditorServer.xml,然后修改Xml配置文件,executable节点改成java,下面的arguments 中指定SpringBoot程序入口Jar包,例如本项目为 mapeditor-1.0.1.jar。
<service> <!-- ID of the service. It should be unique across the Windows system--> <id>MapEditorServer</id> <!-- Display name of the service --> <name>MapEditorServer (powered by WinSW)</name> <!-- Service description --> <description>This service is a service created from a minimal configuration</description> <!-- Path to the executable, which should be started --> <executable>java</executable> <!--Xmx256m 代表堆内存最大值为256MB -jar后面的是项目名--> <arguments>-Xmx256m -jar mapeditor-1.0.1.jar</arguments> <!--日志模式--> <logmode>rotate</logmode> </service>
配置完成后用cmd切至当前目录执行MapEditorServer.exe install 即可完成服务的安装;更多的其他命令如卸载:MapEditorServer.exe uninstall,查看状态:MapEditorServer.exe status等可以到官网自行了解。
用PostMan测试一下,可以正常访问了。
以上就是将SpringBoot的Jar注册成Windows服务的实现方法的详细内容,更多关于SpringBoot的Jar注册成Windows服务的资料请关注脚本之家其它相关文章!
相关文章
Springboot+ElementUi实现评论、回复、点赞功能
这篇文章主要介绍了通过Springboot ElementUi实现评论、回复、点赞功能。如果是自己评论的还可以删除,删除的规则是如果该评论下还有回复,也一并删除。需要的可以参考一下2022-01-01
最新评论