windows 开机运行 springboot 项目/安装为 windows 的服务

这里两天需要将一个 springboot 项目设置为 windows 开机就运行。

网上搜到的方法有用 gpedit.msc 组策略编辑器 来配置。

可是我的电脑是 win7 家庭版,没有 gpedit.msc。

继续搜,搜到了另一个方法:将 springboot 项目安装成 windows 的服务,就能实现 windows 开机就运行 springboot 项目!

操作步骤:

1 下载 WinSW.NET4.exe,在这个链接:github.com/kohsuke/winsw/releases

2 springboot 项目打包成 jar,放到 D:\edrManagement 文件夹里

3 完成 winsw 所需的 xml

<service>
  <id>edrManagement</id>

  <!-- service name  -->
  <name>edrManagement</name>

  <description>This is the edrManagement service</description>

  <!-- java home -->
  <env name="JAVA_HOME" value="%JAVA_HOME%" />
  <executable>java</executable>

  <arguments>-jar "d:\edrManagement\edrManagement-1.jar"</arguments>

  <!-- start on windows loaded -->
  <startmode>Automatic</startmode>
  <!-- service log -->
  <logpath>%BASE%\serviceLog</logpath>
  <logmode>rotate</logmode>
</service>

4 将这个 xml 和 WinSW.NET4.exe 还有 jar 都放到 D 盘的那个里,

xml 改名为 edrManagement.xml, WinSW.NET4.exe 改名为 edrManagement.exe。

扫描二维码关注公众号,回复: 5347178 查看本文章

5 打开 cmd,进入到这个文件夹输入 edrManagement.exe install 安装服务。
安装后,输入 edrManagement.exe start 启动服务。

相关命令如下:
install:安装服务
uninstall:删除服务
start:启动服务
stop:停止服务
restart:重启服务
status:输出当前服务的状态

6 安装成功后,win+R打开运行,输入services.msc, 查看是否有一个叫 edrManagement 的服务,状态为正在运行。
如果状态为正在运行,说明这个 springboot 项目已经运行起来了。

还可以把 停服务,起服务 的命令写成 .bat 脚本,这样重新部署替换 jar 包时比较方便。

shutdown.bat 内容:

d:
cd D:\edrManagement
edrManagement.exe stop

startup.bat 内容:

d:
cd D:\edrManagement
edrManagement.exe start

参考:https://blog.csdn.net/u012489412/article/details/81034375
           https://blog.csdn.net/weixin_40411331/article/details/80193376
另外还有一个 winsw 的介绍:https://www.cnblogs.com/jinanxiaolaohu/p/9695761.html

猜你喜欢

转载自blog.csdn.net/beguile/article/details/86776695