将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服务的资料请关注脚本之家其它相关文章!
相关文章
java并发编程专题(七)----(JUC)ReadWriteLock的用法
这篇文章主要介绍了java ReadWriteLock的用法,文中讲解非常详细,示例代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下2020-07-07
SpringBoot @PostConstruct原理用法解析
这篇文章主要介绍了SpringBoot @PostConstruct原理用法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-08-08


最新评论