当前位置:   article > 正文

windows开机自启动jar包的三种方式_jar文件怎么windows下怎么自启

jar文件怎么windows下怎么自启

方式一、利用组策略,后台静默运行


1.编写运行运行jar包脚本的脚本,如
@echo off
start /d "D:\visitor-services\" startup.bat
@echo on


2.
Windows+R运行,输入gpedit.msc进入组策略编辑器,选中windows设置-启动,然后点击添加脚本即可。

方式二、利用服务(强烈推荐)


1.下载winsw.exe 和.xml(注意:可能需要安装 .net framework4)
地址:https://github.com/winsw/winsw/releases

2.与jar包同路径,同名,改名.exe与.xml并配置 xxx.xml 
配置说明 :https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md

我的配置:

  1. <service>
  2. <!-- ID of the service. It should be unique accross the Windows system-->
  3. <!--服务ID:启动、关闭、删除服务时,都是通过ID来操作的-->
  4. <id>file-service</id>
  5. <!-- Display name of the service -->
  6. <name>file-service</name>
  7. <!-- Service description -->
  8. <description>fileservice</description>
  9. <!-- Path to the executable, which should be started -->
  10. <!--当前电脑配置了java环境变量,直接写成“java”就行;你也可以写成类似这样:D:\develop\jdk1.8\jre\bin\java-->
  11. <executable>java</executable>
  12. <!--<arguments>-jar "C:\Users\Administrator\Desktop\winsw\statement-0.0.1-SNAPSHOT.jar"</arguments>-->
  13. <arguments>-jar file-service.jar -Xms512M -Xmx512M</arguments>
  14. <!--
  15. OPTION: onfailure
  16. Defines a sequence of actions, which should be performed if the managed executable fails.
  17. Supported actions: restart, reboot, none
  18. -->
  19. <onfailure action="restart" delay="10 sec"/>
  20. <onfailure action="restart" delay="20 sec"/>
  21. <!--
  22. OPTION: resetfailure
  23. Time, after which the Windows service resets the failure status.
  24. Default value: 1 day
  25. -->
  26. <resetfailure>1 hour</resetfailure>
  27. <!--
  28. OPTION: priority
  29. Desired process priority.
  30. Possible values: Normal, Idle, High, RealTime, BelowNormal, AboveNormal
  31. Default value: Normal
  32. -->
  33. <priority>Normal</priority>
  34. <!--
  35. OPTION: stoptimeout
  36. Time to wait for the service to gracefully shutdown the executable before we forcibly kill it
  37. Default value: 15 seconds
  38. -->
  39. <stoptimeout>15 sec</stoptimeout>
  40. <!--
  41. OPTION: stopparentprocessfirst
  42. If set, WinSW will terminate the parent process before stopping the children.
  43. Default value: false
  44. -->
  45. <stopparentprocessfirst>false</stopparentprocessfirst>
  46. <!--
  47. OPTION: startmode
  48. Defines start mode of the service.
  49. Supported modes: Automatic, Manual, Boot, System (latter ones are supported for driver services only)
  50. Default mode: Automatic
  51. -->
  52. <startmode>Automatic</startmode>
  53. <waithint>15 sec</waithint>
  54. <sleeptime>1 sec</sleeptime>
  55. <log mode="roll-by-size">
  56. <sizeThreshold>10240</sizeThreshold>
  57. <keepFiles>8</keepFiles>
  58. </log>
  59. </service>

3.cmd命令行,输入 xxx.exe install 安装服务

如果权限不足,需要进入c:\windows\System32 目录下,用管理员权限运行cmd
4.net start xxx 启动服务

net stop xxx 关闭服务

sc delete xxx 删除服务

方式三、添加到启动项,前台运行


把bat脚本,或者.exe快捷方式放进去即可

总结:

实际使用过程中,比较推荐部署成服务的方式,易于维护和管理。

交流q群:791117516

参考资料:

https://blog.csdn.net/lee008108/article/details/78713385

https://blog.csdn.net/Pruett/article/details/92813229

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/76364
推荐阅读
相关标签
  

闽ICP备14008679号