jar注册为windows服务并启动

本是古典 何须时尚 2023-01-13 10:10 326阅读 0赞

1、服务注册工具WinSW.NET4.exe

  1. https://github.com/kohsuke/winsw/releases

2、将exe改为ja包名称,也是服务对应的名称

在这里插入图片描述

3、创建服务名.xml文件

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <service>
  3. <!-- ID of the service. It should be unique across the Windows system-->
  4. <id>JPA_Test-1.0-SNAPSHOT</id>
  5. <!-- Display name of the service -->
  6. <name>JPA_Test-1.0-SNAPSHOT</name>
  7. <!-- Service description -->
  8. <description>注册到win服务的JPA_Test-1.0-SNAPSHOT.jar</description>
  9. <!-- Path to the executable, which should be started -->
  10. <executable>java</executable>
  11. <arguments> -server -Xms64m -Xmx128m -XX:PermSize=64M -XX:MaxPermSize=128M -jar -Dfile.encoding=UTF-8 %BASE%\JPA_Test-1.0-SNAPSHOT.jar</arguments>
  12. <logpath>%BASE%\logs</logpath>
  13. <log mode="roll-by-size">
  14. <sizeThreshold>5120</sizeThreshold>
  15. <keepFiles>7</keepFiles>
  16. </log>
  17. </service>

4、创建注册并启动的脚本Install.bat

  1. @echo off
  2. JPA_Test-1.0-SNAPSHOT.exe install
  3. sc start JPA_Test-1.0-SNAPSHOT
  4. exit

在这里插入图片描述
并且会自动生成log启动日志文件:
在这里插入图片描述

5、创建停止并删除服务的脚本UnInstall.bat

  1. @echo off
  2. sc stop JPA_Test-1.0-SNAPSHOT
  3. JPA_Test-1.0-SNAPSHOT.exe uninstall
  4. exit

发表评论

表情:
评论列表 (有 0 条评论,326人围观)

还没有评论,来说两句吧...

相关阅读