记录一次jar文件在windows系统下开机自启

自启有很多中方式,其中最好维护的一种方式是把启动命令注册成服务

  1. 首先去 https://github.com/kohsuke/winsw/releases 下载WinSW软件
  2. 我这里找的2.x的版本,3.x的版本是压缩包,下载这个exe和xml文件
    在这里插入图片描述3. 下载下来以后把文件放到jar包同目录下,并改为同名,像这样(这里的日志文件是我服务启动之后自动生成的)
    在这里插入图片描述4. 下面我们修改一下xml文件的配置
<service>
  <!-- ID of the service. It should be unique accross the Windows system-->
    <!--服务ID:启动、关闭、删除服务时,都是通过ID来操作的-->
  <id>project-materials</id>
  <!-- Display name of the service -->
  <name>project-materials</name>
  <!-- Service description -->
  <description>project-materials</description>
  
  <!-- Path to the executable, which should be started -->
    <!--当前电脑配置了java环境变量,直接写成“java”就行;你也可以写成类似这样:D:\develop\jdk1.8\jre\bin\java-->
  <executable>java</executable>
    <!--<arguments>-jar "C:\Users\Administrator\Desktop\winsw\statement-0.0.1-SNAPSHOT.jar"</arguments>-->
  <arguments>-jar project-materials.jar -Xms512M -Xmx512M</arguments>
 
  <!--
    OPTION: onfailure
    Defines a sequence of actions, which should be performed if the managed executable fails.
    Supported actions: restart, reboot, none
  -->
  <onfailure action="restart" delay="10 sec"/>
  <onfailure action="restart" delay="20 sec"/>
  <!--
    OPTION: resetfailure
    Time, after which the Windows service resets the failure status.
    Default value: 1 day
  -->
  <resetfailure>1 hour</resetfailure>
  <!--
    OPTION: priority
    Desired process priority.
    Possible values: Normal, Idle, High, RealTime, BelowNormal, AboveNormal
    Default value: Normal
  -->
  <priority>Normal</priority>
  
  <!-- 
    OPTION: stoptimeout
    Time to wait for the service to gracefully shutdown the executable before we forcibly kill it
    Default value: 15 seconds
  -->
  <stoptimeout>15 sec</stoptimeout>
    
  <!--
    OPTION: stopparentprocessfirst
    If set, WinSW will terminate the parent process before stopping the children.
    Default value: false
  -->
  <stopparentprocessfirst>false</stopparentprocessfirst>
 
    <!--
      OPTION: startmode
      Defines start mode of the service.
      Supported modes: Automatic, Manual, Boot, System (latter ones are supported for driver services only)
      Default mode: Automatic
    -->
    <startmode>Automatic</startmode>
    <waithint>15 sec</waithint>
    <sleeptime>1 sec</sleeptime>
  <log mode="roll-by-size">
  <sizeThreshold>10240</sizeThreshold>
  <keepFiles>8</keepFiles>
</log>
</service>
  1. 下面就可以注册服务了
    使用cmd打开命令端口
    3.1 xxx.exe install
    3.2 net start xxx (这个xxx是你在xml文件中配置的服务名)
    在这里插入图片描述

  2. net stop xxx 关闭服务

  3. sc delete xxx 删除服务

使用windows启动文件夹自启程序

首先建立shell命令文件,文件后缀vbs

// 程序文件路径写自己的
createobject("wscript.shell").run"D:\重大危险源研判\后台\启动脚本.bat",0

在这里插入图片描述然后建立快捷方式,将它放入windows启动文件夹里
windows启动文件夹查找方式:
按Win+R键打开运行窗口,输入“shell:Common Startup”代码

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值