windows开机自启动jar包的三种方式
方式一、利用组策略,后台静默运行
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
我的配置:
<service><!-- ID of the service. It should be unique accross the Windows system--><!--服务ID:启动、关闭、删除服务时,都是通过ID来操作的--><id>file-service</id><!-- Display name of the service --><name>file-service</name><!-- Service description --><description>fileservice</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 file-service.jar -Xms512M -Xmx512M</arguments><!--OPTION: onfailureDefines 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: resetfailureTime, after which the Windows service resets the failure status.Default value: 1 day--><resetfailure>1 hour</resetfailure><!--OPTION: priorityDesired process priority.Possible values: Normal, Idle, High, RealTime, BelowNormal, AboveNormalDefault value: Normal--><priority>Normal</priority><!-- OPTION: stoptimeoutTime to wait for the service to gracefully shutdown the executable before we forcibly kill itDefault value: 15 seconds--><stoptimeout>15 sec</stoptimeout><!--OPTION: stopparentprocessfirstIf set, WinSW will terminate the parent process before stopping the children.Default value: false--><stopparentprocessfirst>false</stopparentprocessfirst><!--OPTION: startmodeDefines 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>
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
windows开机自启动jar包的三种方式相关推荐
- Intellij IDEA 添加jar包的三种方式
Intellij IDEA 添加jar包的三种方式 inzaghihalo https://blog.csdn.net/superinzaghi747/article/details/80539095 ...
- Windows开机自启动jar包
在Windows环境设置开机自启动jar包的核心思想就是把启动命令注册成一个服务,然后就可以设置开机自启动了.手写一个注册服务代码比较麻烦,可以借助线程的exe可执行文件来做. 首先去https:// ...
- idea 单独引入jar_Intellij IDEA 添加jar包的三种方式
一.直接复制:(不推荐) 方法:直接将硬盘上的jar包复制粘贴到项目的lib目录下即可. 注意: 1.对于导入的eclipse项目,该方式添加的jar包没有任何反应,用make编译项目会报错 2.对于 ...
- idea新增jar_Intellij IDEA 添加jar包的三种方式(小结)
一.直接复制:(不推荐) 方法:直接将硬盘上的jar包复制粘贴到项目的lib目录下即可. 注意: 1.对于导入的eclipse项目,该方式添加的jar包没有任何反应,用make编译项目会报错 2.对于 ...
- Maven打jar包的三种方式
不包含依赖jar包 该方法打包的jar,不包含依赖的jar包,也没有指定入口类. <build><plugins><plugin><!-- 指定项目编译时的j ...
- Linux开机自启动jar包详细操作,认真看完肯定可以完成
Linux开机自启动jar包脚本 有xshll和xftp的可以直接在Windows系统下创建一个txt文件贴上以下代码 #!/bin/sh export JAVA_HOME=你Linux系统下的jav ...
- Eclipse下导入外部jar包的3种方式
转载自 Eclipse下导入外部jar包的3种方式 我们在用Eclipse开发程序的时候,经常要用到第三方jar包.引入jar包不是一个小问题,由于jar包位置不清楚,而浪费时间.下面配图说明3 ...
- Linux 运行jar包的几种方式
nohup java -jar wechat-push-0.0.1-SNAPSHOT.jar > wechat-push-0.0.1.out 2>&1 & 一.Linux ...
- 全网最全Linux 运行jar包的几种方式
一.Linux 运行jar包的几种方式 方式一: java -jar xxx.jar 最常用的启动jar包命令,特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 ...
最新文章
- php动态加载js,动态加载script文件的两种方法_javascript技巧
- JavaScript中的遍历详解
- linux中的keeplived源码装,keepalived源码安装及主备配置
- 【测试】SAP选择屏幕界面配图实现
- cobbler自动化安装详解
- 在树莓派是安装并配置NTP服务
- 【loj6191】「美团 CodeM 复赛」配对游戏 概率期望dp
- 物理机安装ESXI6.7提示No Network Adapters的解决方案
- 轨迹相似性度量方法总结
- CCF201712试题
- FR获取当前控件位置值并转换(或赋值可参考)
- android进阶指导
- Remote Desktop Connection 7.0
- Tomcat8配置SSL证书
- 游记_秦皇岛-北戴河两日游
- 特斯拉设计师评苹果造车:痴人说梦,缺乏创新
- Rosalind第八题:将RNA转化成蛋白质
- python爬取12306列车信息自动抢票并自动识别验证码(二)selenium登录验证篇
- 今天来聊一聊互联网35岁梗,这个行业真的不需要35岁以上从业人员?
- 【栈的应用】括号的分数