采用WinSW将jar包做成window本地服务
效果
- 把jar包做成window的本地服务 (查看方式:win+r 输入 services.msc 点击确定 )
2. 接口访问测试
实现过程
- 需要三个文件
-
.jar 文件 是通过idea打包得到的(自己提供)
-
.exe 和 .xml 是通过 winsw github仓库下载的
-
-
.xml文件内容的配置:
id:唯一标识,我设为jar包的名称
name:服务中展示的名字
description:服务描述
executable:java 或 jdk路径
arguments:执行的命令和jar包路径<service><!-- ID of the service. It should be unique across the Windows system--><id>study-spring-boot</id><!-- Display name of the service --><name>study-spring-boot</name><!-- Service description --><description>一个springboot 打包的jar包</description><!-- Path to the executable, which should be started --><executable>java</executable><arguments>-jar study-spring-boot.jar</arguments> </service>
注意: 文件名称统一改成一样(名字自定义的,三个文件名称统一就行)
- 打开window 的dom窗口,以管理员身份打开 (win+s 输入cmd)
点击打开即可,进入到上面三个文件的目录 (至于怎么进入就不说了,太简单了)
-
输入 study-spring-boot.exe install (study-spring-boot 就是自定义的名称,也是后面生成的服务的名称)
study-spring-boot.exe install
然后切换到刚刚打开的服务窗口,刷新一下,就可以查看到多了一个 study-spring-boot 的服务 -
如何想删除该服务,只需要在上面的窗口,输入 study-spring-boot.exe uninstall 就删除了,再去服务窗口,刷新一下,改服务就没了
study-spring-boot.exe uninstall
提示: 不管是 study-spring-boot.exe install 还是 study-spring-boot.exe uninstall 这两个命令,study-spring-boot是你自定义的文件名称(也就是最开始上面三个文件的名称,同时也是后面生成的服务的名称,你自定义的是啥,你就统一把 study-spring-boot 换成你自定义的就行)
-
补充:重启动和停止服务命令 (其实也可以通过服务窗口的面板来操作)
① 重启动服务命令study-spring-boot.exe restart
① 停止服务命令
study-spring-boot.exe stop
服务窗口面板操作
- 结束.