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