整理相关实现Java的jar注册为系统服务的方法
发布日期:2021-10-10 12:33:25 浏览次数:2 分类:技术文章

本文共 1672 字,大约阅读时间需要 5 分钟。

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

1、WinSW实现注册Jar包服务

下载地址:

我这里下载的是WinSW.NET4.exe,看个人的需求吧!

  • 准备相关的文件信息

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

    Demo-admin
    Demo-admin
    一个测试服务 Demo-admin
    java
    -jar Demo-admin-1.0.0.jar
    Automatic
    %BASE%\log
    rotate
  • 相关文件信息如下:

    在这里插入图片描述

  • 创建服务信息

    打开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 相关的命令语句:

地址:

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

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

下载地址:

注意的是这个软件有好几个版本,下载框了红框的社区版是不需要License啥的

在这里插入图片描述
相对WinSW有点繁琐,但是它支持好几种平台,功能相对强悍些

后续整理发现中。。。

转载地址:https://blog.csdn.net/qq_26848943/article/details/109165303 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SpringBoot配置日志文件输出
下一篇:整理 Tomcat 相关的部署知识

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月21日 17时34分44秒