Windows系统部署jar包为服务

推荐使用WinSW

下载地址:

下载WinSW-x64.exe,sample-minimal.xml两个文件;32位系统下载WinSW-x86.exe

sample-minimal.xml文件说明:

<service>
     <!-- 服务的ID,必须唯一 -->
     <id>myServiceID</id> 
     <!-- 服务的名称 -->
     <name>MyService</name>
     <!-- 服务的描述 -->
     <description>该服务基于springboot框架。</description>
     <!-- java环境变量 -->
     <env name="JAVA_HOME" value="%JAVA_HOME%" />
     <executable>java</executable> 
     <!-- jar包位置,%BASE%:自动识别当前文件夹 -->	
     <arguments>-jar %BASE%myservice.jar</arguments>
     <!-- 开机自动启动模式:Automatic(默认) -->
     <!-- 手动启动:Manaul -->
     <startmode>Automatic</startmode>
     <!-- 日志配置 -->
     <logpath>%BASE%log</logpath>
     <logmode>rotate</logmode>
</service>

安装步骤:

1、将WinSW-x64.exe和sample-minimal.xml名称修改为对应jar包的名称,并放到jar包所在文件夹下

2、在jar包所在文件夹运行cmd命令
安装服务命令:
myservice.exe install
卸载服务命令:
myservice.exe uninstall
启动服务命令:
myservice.exe start
停止服务命令:
myservice.exe stop
重启服务命令:
myservice.exe restart
查看服务运行状态:
myservice.exe status
经验分享 程序员 微信小程序 职场和发展