springboot程序在windows上部署开机自启

1、下载 WinSW.NET4.exe (下载路径: https://github.com/kohsuke/winsw/releases

 

2、将 WinSW.NET4.exe 复制到待部署的 jar 文件路径下,将 WinSW.NET4.exe 的文件名改为和 jar 文件一样

  例如: test-1.jar 对应的 exe文件名就是 test-1.exe

3、新建 xml 配置文件,xml的文件名也和 jar 的文件名相同,xml 的内容如下,这里假设我们要运行的 jar 文件就是 test-1.jar:

 

<?xml version="1.0" encoding="UTF-8"?>
<service>
    <!-- 服务ID -->
    <id>test-1</id>
    <!-- 服务名称 -->
    <name>test-1</name>
    <!-- 服务描述 -->
    <description>This service runs test-1 continuous integration system.</description>
    <!-- jar包运行参数 -->
    <executable>java</executable>
    <arguments>-Xrs -Xmx256m -jar "%BASE%\test-1.jar" --server.port=1009</arguments>
    <!-- 日志配置 -->
    <logpath>%BASE%\log</logpath>
    <logmode>rotate</logmode>
</service>

 

最终的三个文件为:

 

xxx.exe
xxx.jar
xxx.xml

 

4、注册服务,cmd 切换到 jar 文件路径,执行 xxx.exe install (如上述示例,这里就应该执行 test-1.exe install)

5、在服务列表中找到刚才的服务,启动即可,或者重启之后便自动会启动了。

6、如果要卸载服务,只需要在 cmd 运行: sc delete [服务名]

posted @ 2019-10-24 09:50  lkc9  阅读(2362)  评论(0编辑  收藏  举报