失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > windows开机自启动jar包的三种方式

windows开机自启动jar包的三种方式

时间:2018-11-16 07:34:54

相关推荐

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)

地址:/winsw/winsw/releases

2.与jar包同路径,同名,改名.exe与.xml并配置 xxx.xml

配置说明 :/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

start xxx 启动服务

net stop xxx 关闭服务

sc delete xxx 删除服务

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

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

总结:

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

交流q群:791117516

参考资料:

/lee008108/article/details/78713385

/Pruett/article/details/92813229

如果觉得《windows开机自启动jar包的三种方式》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。