Skip to content

Spring Boot项目编译的jar在windows下作为service执行

GeXiangDong edited this page Jan 9, 2019 · 4 revisions

可以使用Windows service wrapper来把任何命令行执行的程序做成windows service.

Windows Service Wrapper简称WinSW,可以在https://github.com/kohsuke/winsw/releases 下载到

编写一个配置文件

编写一个xml文件,可参照下例:

<configuration>
  <id>tutorial-service</id>
  <name>Tutorial Service</name>
  <description></description>
  <executable>java</executable>
  <arguments>-jar c:\tutorial\tutorial-section-01-1.0-SNAPSHOT.jar</arguments>
  <logmode>rotate</logmode>
</configuration>

文件保存为 tutorial-service.xml,然后把winsw.exe拷贝到相同目录下,并改成和xml一样的名字(扩展名仍旧是exe不变)tutorial-service.exe

安装service和卸载service

在命令行下执行

tutorial-service.exe install

可把前面设置的xml中命令安装为windows service(执行上述命名需要具有windows管理员权限。

如果需要卸载可用

tutorial-service.exe uninstall