參考:
https://www.jianshu.com/p/fc9e4ea61e13
https://blog.csdn.net/qq_28566071/article/details/80882503
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
下載文件:
需要將winsw執行程序跟xml改成同樣的名字:
修改spider-1.0.xml文件內容
<configuration> <id>SpiderService</id> <name>SpiderService</name> <description>This is Spider service.</description> <executable>java</executable> <arguments>-jar spider-1.0.jar</arguments> <!-- 開機啟動 --> <startmode>Automatic</startmode> <!-- 日志配置 --> <logpath>logs/service</logpath> <logmode>rotate</logmode> </configuration>
配置完成后,命令行進入winsw所在的文件夾,執行“spider-1.0.exe install”,就注冊服務了。
如果不再需要這個服務,使用spider-1.0.exe uninstall即可卸載服務。start啟動和stop關閉服務