Make the Jar package into a Win service, and set it to start automatically at boot


foreword

提示:开机无感启动后台服务(jar包)

Make the jar package as a service of the Win system, and set it to start automatically.
After the computer is turned on, the background service is automatically started. This article is in the form of a jar package.


1. Preparation tools

  1. your jar package
  2. WinSW-x64.exe
  3. sample-minimal.xml

Download address: https://github.com/winsw/winsw/releases
download WinSW-x64.exe , sample-minimal.xml two files
insert image description here

2. Start configuring the service

  1. Create an empty folder locally, put the jar package and the two downloaded files into it,
    and rename the name to the same name, and create a new log folder (for storing logs)
    insert image description here
  2. Edit the sample-minimal.xml file (.xml file)
<service>
  <!-- 服务id在windows系统中必须唯一 -->
  <id>myapp</id>  
  <!-- 服务显示名称 -->
  <name>MyApp Service (powered by WinSW)</name> 
  <!-- Service description -->
  <description>This service is a service created from a minimal configuration</description> 
  <!-- java环境变量 -->
  <env name="JAVA_HOME" value="%JAVA_HOME%" />
  <executable>java</executable>
  <!-- jar包位置, %BASE%:自动识别当前文件夹 -->
  <arguments>-jar %BASE%\test.jar</arguments>
  
  <!-- 开机自动启动模式:Automatic(默认) -->
  <!-- 手动启动: Manual -->
  <startmode>Automatic</startmode>
  
  <!-- 日志相关配置 -->
  <logpath>%BASE%\log</logpath>
  <logmode>rotate</logmode>

</service>

3. Add services

1. Enter cmd in the search box at the top of the current file to open the command window
insert image description here
2. Enter the command to add a service
: test.exe install
insert image description here
3. Open the computer service to check that it has been successfully added to the service item 4. Other commands
注意:此处的名称是根据sample-minimal.xml文件中的<name>标签命名
insert image description here

Add service: test.exe install
Start service: test.exe start
Stop service: test.exe stop
Uninstall service: test.exe uninstall
Restart service: test.exe restart
View status: test.exe status

Summarize

Tip: The above are the steps I summarized to start the background service without feeling the boot.

Guess you like

Origin blog.csdn.net/SmallCat0912/article/details/127426885