<service>
<!-- windows 服务唯一标识id-->
<id>my server</id>
<!-- windows 服务名称-->
<name>my server</name>
<!-- windows 服务描述-->
<description>this service is a service cratead from a minimal configuration</description>
<!-- 启动的可执行文件的路径,如果已经配置环境变量,则不必写全路径(则其实是一个坑) -->
<executable>java</executable>
<arguments> -jar myserver.jar --spring.datasource.url=jdbc:mysql://localhost:3306/database </arguments>
<!-- 日志路径,若目录不存在,则默认为配置文件所在的同一目录-->
<logpath>serverpath\log\dashboard\</logpath>
<!-- 日志模式,默认为append追加模型,rotate为旋转模式-->
<logmode>rotate</logmode>
</service>
service cannot be started.
system.componentmodel.win32exception: the system cannot find the file specified
at system.diagnostics.process.startwithcreateprocess(processstartinfo startinfo)
at winsw.wrapperservice.startprocess(process processtostart, string arguments, string executable)
at winsw.wrapperservice.onstart(string[] _)
at system.serviceprocess.servicebase.servicequeuedmaincallback(object state)
@echo off
# 获取java环境变量
set java_home=%java_home%
echo %java_home%
# 替换java路径
setlocal enabledelayedexpansion
set file=%cd%\myserver.xml
set file_tmp=%cd%\myserver_tmp.xml
set source=javahome
set replaced=%java_home%\bin\java
for /f "delims=" %%i in (%file%) do (
set str=%%i
set "str=!str:%source%=%replaced%!"
echo !str!>>%file_tmp%
)
move "%file_tmp%" "%file%"
# 注册并启动服务
myserver.exe uninstall
myserver.exe install
myserver.exe start
exit