1.下载 winsw.exe文件,地址:https://github.com/winsw/winsw
windiws 上的 .NET framework 版本 要 是4.6或以上。
2. 注册 jar
将下载下来的 winsw.exe 修改成 jar文件同名。并在同目录创建一个 同名的xml
text.xml文件配置:
<service>
<id>test</id> <!-- 服务id,必须唯一 -->
<name>test</name> <!-- 服务名称 -->
<description>测试</description> <!-- 服务描述 -->
<executable>java</executable>
<arguments>-jar D:\test.jar</arguments> <!-- 指定jar包的路径 ,启动命令 -->
<logpath>.\log</logpath> <!-- 日志路径 -->
<startmode>Automatic</startmode> <!-- 设置服务自动启动 -->
<logmode>reset</logmode>
</service>
3. 在 test.exe 目录下 启动 cmd 执行: test.exe install
执行成功,会生成一个log 文件夹,到windows 服务中查看,test 服务已经创建成功。
4.注册bat文件 xml文件配置,启动方式同上
<service>
<id>minio</id>
<name>minio</name>
<description>minio服务端</description>
<executable>d:\minio\start.bat</executable> <!-- 指定bat文件的路径 -->
<logpath>.\log</logpath>
<startmode>Automatic</startmode>
<logmode>reset</logmode>
</service>
删除服务命令 sc delete 服务名称
启动服务命令 net start 服务名称
停止服务命令 net stop 服务名称