使用 winsw 将jar 或 bat文件注册到 windows 服务

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 服务名称

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值