整理相关实现Java的jar注册为系统服务的方法

4 篇文章 0 订阅
2 篇文章 0 订阅

在开发运维中,比如现在比较流行的Spring-Boot这种微服务,在Windows上面实现打包运行啥的有个控制台窗口,如果不注意关了服务就GG了,这里整理一些相关的Windows上注册Java的Jar为服务的方法等。

1、WinSW实现注册Jar包服务

下载地址:https://github.com/winsw/winsw/releases
我这里下载的是WinSW.NET4.exe,看个人的需求吧!

  • 准备相关的文件信息
    创建一个空文件夹,放入下载的WinSW.NET4.exe、打包的Jar包,创建一个WinSW.NET4.xml文件,文件内容如下(注意,文件名称必须和WinSW.NET4.exe名称一致,可自定义):

    <service>
        <id>Demo-admin</id>
        <name>Demo-admin</name>
    	<description>一个测试服务 Demo-admin</description>
    	<!-- java环境变量 -->
    	<!-- 配置了环境变量 写java 否则写jdk绝对路径-->
        <executable>java</executable>
    	<!-- 可以绝对路径 可以相对路径-->
        <arguments>-jar Demo-admin-1.0.0.jar</arguments>
    	<!-- 开机启动 -->
    	<startmode>Automatic</startmode>
    	<!-- 日志配置 -->
    	<logpath>%BASE%\log</logpath>
        <logmode>rotate</logmode>
    </service>
    
  • 相关文件信息如下:
    在这里插入图片描述

  • 创建服务信息
    打开CMD命令窗口,输入如下命令即可:

    WinSW.NET4.exe install 
    
    # 得到如下信息:
    2020-10-19 17:59:55,784 INFO  - Installing the service with id 'Demo-admin'
    

    貌似win10系统有个确认框什么的,点击确认就行了,

    打开Windows服务窗口,发现服务注册成功了,而且是能自启的,如下:
    在这里插入图片描述
    好像有些博客说的是还要创建 创建服务 install.bat 和 卸载服务 uninstall.bat 这种批处理文件啥的,好像最新的WinSW不需要创建了,应该能减少一些错误情况吧
    这种方法还是蛮简单的,亲测可用

WinSW 相关的命令语句:
地址: https://github.com/winsw/winsw/blob/v3/docs/cli-commands.md#install-command

  install     install the service to Windows Service Controller
  uninstall   uninstall the service
  start       start the service (must be installed before)
  stop        stop the service
  stopwait    stop the service and wait until it's actually stopped
  restart     restart the service
  restart!    self-restart (can be called from child processes)
  status      check the current status of the service
  test        check if the service can be started and then stopped
  testwait    starts the service and waits until a key is pressed then stops the service
  version     print the version info

2、wrapper-windows

这种方式我试了一下,不知道哪儿配置错了,好像有点问题,这里提供一个下载地址吧!

下载地址:https://wrapper.tanukisoftware.com/doc/english/download.jsp

注意的是这个软件有好几个版本,下载框了红框的社区版是不需要License啥的
在这里插入图片描述
相对WinSW有点繁琐,但是它支持好几种平台,功能相对强悍些

后续整理发现中。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值