- 首先准备好需要启动的jar包,xxx.jar
- 到github上下载winsw文件,地址 https://github.com/winsw/winsw/releases
winsw下载
如图,只需要下载以上两个文件即可,其中exe文件的版本根据系统上安装的.net版本决定。 -
修改文件名:将下载好的文件放到一个空的文件夹下,并将文件名改成一致。
修改文件名 - 修改配置文件如下
<service>
<!-- ID of the service. It should be unique across the Windows system(服务编号)-->
<id>personCarSync</id>
<!-- Display name of the service 服务名称 -->
<name>personCarSync Service (powered by WinSW)</name>
<!-- Service description 服务描述 -->
<description>This service is a service created from a minimal configuration</description>
<!-- Path to the executable, which should be started,执行程序,需要预先配置java环境 -->
<executable>java</executable>
<!-- java run arguements 运行参数 -->
<arguments>-jar person-car-sync-1.0-SNAPSHOT.jar --spring.profiles.active=xxqt</arguments>
</service>
-
安装服务
将准备好的jar包文件也放到文件夹下,并在当前目录打开控制台,执行安装服务指令:
jar包
-
运行服务
在控制台执行net start personCarSync 即可:
启动服务
如果执行提示“拒绝访问”,则需要手动启动服务,打开运行输入 services.msc ,在服务中找到刚刚创建的服务,手动启动即可:
手动启动服务 - 自启动
也可将服务设置为自启动,当系统启动时自启动该服务。
网友评论