1蛾坯、下載 WinSW.NET4.exe (下載路徑:?https://github.com/winsw/winsw/releases?)
2仇味、將 WinSW.NET4.exe 復制到待部署的 jar 文件路徑下吁津,將 WinSW.NET4.exe 的文件名改為和 jar 文件一樣
例如: test-1.jar 對應的 exe文件名就是 test-1.exe
3加派、新建 xml 配置文件残邀,xml的文件名也和 jar 的文件名相同开睡,xml 的內(nèi)容如下,這里假設我們要運行的 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包運行參數(shù) -->
? ? <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 文件路徑文捶,執(zhí)行 xxx.exe install (如上述示例荷逞,這里就應該執(zhí)行 test-1.exe install)
5、在服務列表中找到剛才的服務粹排,啟動即可种远,或者重啟之后便自動會啟動了。
6顽耳、如果要卸載服務坠敷,只需要在 cmd 運行: sc delete [服務名]