1. Download winsw
Enter the winsw official website to download the WinSW-x64.exe file (it can also be downloaded together with the sample-minimal.xml file)
address: https://github.com/winsw/winsw/releases
- Put your own jar package and the newly downloaded exe file and xml file into an empty folder
- Rename all exe files and xml files to the same name as .jar
- Create a new folder named log to store log files
Two, edit the xml file
The official website indicates that service must be used as the root element of the xml file
<service>
<id>testWinswService</id> <!-- 服务id在windows系统中必须唯一 -->
<name>myService</name> <!-- 服务显示名称 -->
<description>This Service is designed to show winsw.</description>
<!-- java环境变量 -->
<env name="JAVA_HOME" value="%JAVA_HOME%" />
<executable>java</executable>
<!-- jar包所在路径 -->
<arguments>-jar "D:\winsw\testWinsw-1.0.1.jar"</arguments>
<!-- 开机自动启动模式:Automatic(默认) -->
<!-- 手动启动: Manual -->
<startmode>Automatic</startmode>
<!-- 日志相关配置 -->
<logpath>%BASE%\log</logpath>
<logmode>rotate</logmode>
</service>
3. Deploy and run
Enter cmd in the path where the jar package is located to enter the command window
Enter the deploy command:testWinsw-1.0.1.exe install
Start command:testWinsw-1.0.1.exe start
other commands
Stop service: XXX.exe stop
Uninstall service: XXX.exe uninstall
Restart service: XXX.exe restart
View status: XXX.exe status
4. Check the service
You can view it in computer management according to the service name (right-click this computer and click manage to enter)
You can also view it in the task manager according to the service id
Finish