Springboot注册为Windows系统服务

  • 阶段1:Bat文件启动Jar

1、新建一个名为example.bat,打开编辑,写入以下内容:

cd E:/springboot
java -jar example-dev.jar
exit

2、然后保存。双击example.bat启动项目。

  • 阶段2:Windows启动菜单添加快捷方式启动

1、win+R打开运行窗口,输入shell:startup;

2、将example.bat创建快捷方式,然后将快捷方式拷贝到启动项文件中。

  • 阶段3:使用winsw将Springboot打包的jar注册系统本地服务

1、从github上下载winsw,下载地址https://github.com/kohsuke/winsw;

2、下载WinSW.NET4.exe,这个是支持.netframework4.0的版本,如果没有.net4.0,请先安装.net4.0,下载后改名成你想启动的服务名字(比如:example.exe);

3、新建一个example.xml文件,编写一下配置内容:

 
     example 
      example 
     This is example service.
     
     
     java 
    -jar "E:\springboot\example-dev.jar"
     
     Automatic
     
     %BASE%\log
     rotate
 

4、保存example.xml文件,将example.xml和example.exe放到要启动的jar的同级目录下(例如:E:\springboot\);

5、打开cmd,进入到E:\springboot;输入example.exe install安装服务。安装后,输入example.exe start启动服务;

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

6、安装成功后,win+R打开运行,输入services.msc,查看是否有一个叫example的服务,运行状态是否为正在运行。

你可能感兴趣的:(Springboot)