1.下载winsw工具
只需下载图中红框的工具
https://github.com/winsw/winsw/releases
2.文件配置
将下载的文件与jar文件放置在一起,两个文件名修改为服务名
编辑xml文件
注意不要出现中文, 标签内的jar文件地址要改为自己目录
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>testapp</id>
<!-- Display name of the service -->
<name>test service</name>
<!-- Service description -->
<description>This service is a service created from a minimal configuration</description>
<env name="JAVA_HOME" value="%JAVA_HOME%"/>
<executable>java</executable>
<arguments>-jar "H:\testautostart\cxstar-api-rest-1.0.0.jar"</arguments>
<startmode>Automatic</startmode>
</service>
3.注册服务
当前目录输入cmd,进入命令行模式,执行服务注册命令
testapp.exe install
服务中已经存在该服务
双击设置为自动即可
4.卸载服务
testapp.exe uninstall