1. winsw下載
去github上面下載winsw https://github.com/winsw/winsw/releases 需要下載 WinSW.NET4.exe 和 sample-minimal.xml
2. 修改sample-minimal.xml文件內容
<service>
<id>admin</id>
<name>admin</name>
<description>This service runs admin project.</description>
<!-- java環境變量 -->
<env name="JAVA_HOME" value="%JAVA_HOME%"/>
<executable>java</executable>
<!-- 需要執行的命令 -->
<arguments>-jar "../server/admin.jar" --spring.config.location=../conf/</arguments>
<!-- 開機啓動 -->
<startmode>Automatic</startmode>
<!-- 日誌配置 -->
<logpath>../Logger</logpath>
<logmode>rotate</logmode>
</service>
3. 修改文件名
把 WinSW.NET4.exe 和 sample-minimal.xml 分別重命名爲 admin.exe、admin.xml [和xml文件中id同名]。
4. 編寫腳本
編寫啓動腳本 run.bat
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd "%~dp0"
cd ../win
admin.exe install
net start admin
exit
編寫停止腳本 stop.bat
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd "%~dp0"
cd ../win
net stop admin
admin.exe uninstall
exit