用winsw将jar包做成window后台服务

把jar包做成windows后台服务,这样就可以开机自启动了。

1、下载Winsw.exe

Winsw.exe文件下载路径:https://github.com/winsw/winsw/releasesimage.png

2、编写配置文件sample.xml

<service>

 <id>sample</id>

 <name>sample</name>

 <description>This service runs sample system.</description>

 <executable>java</executable>

 <arguments>-Xrs -Xmx256m -jar "%BASE%\sample.jar" </arguments>

 <log mode="roll" />

 <onfailure action="restart" />

</service>

3、修改为同样的名称

把sample.jar、sample.xml、winsw.exe 放到同一目录,并且修改为和jar包同样的名称

修改前

image.png

修改后:

image.png

4、安装sample服务

打开CMD命令行,并切换到jar所在目录,运行 sample install 命令进行服务安装

image.png

此时就可以在后台中查看windows服务了。但是此时程序还是未启动状态

image.png

5、启动服务

1)界面启动:在sample服务上面右键,选择启动。或者双击sample服务,打开属性窗口,点击启动。

image.png

image.png

2)命令行启动

切换到jar包所在目录运行 sample start

image.png

6、其他一些命令行操作指令

 install     install the service to Windows Service Controller

 uninstall   uninstall the service

 start       start the service (must be installed before)

 stop        stop the service

 stopwait    stop the service and wait until it's actually stopped

 restart     restart the service

 restart!    self-restart (can be called from child processes)

 status      check the current status of the service

 test        check if the service can be started and then stopped

 testwait    starts the service and waits until a key is pressed then stops the service

 version     print the version info

 help        print the help info (aliases: -h,--help,-?,/?)

猜你喜欢

转载自blog.csdn.net/forgetmiss/article/details/116454671