背景:最近维护老项目,需要使用windows server 2012 r2部署项目。使用springboot开发项目,nginx部署前端,于是打算把jar包和nginx都制作成服务
下载winsw地址:https://github.com/winsw/winsw/releases
下载这两个文件后,跟你需要制作jar包的路径放一起。有个问题要注意,WinSW.NET4.exe和sample-minimal.xml 修改后的文件名要一致,比如winsw.exe、winsw.xml不然会报错,这个要注意。
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>myapp</id>
<!-- Display name of the service -->
<name>MyApp Service (powered by WinSW)</name>
<!-- Service description -->
<description>This service is a service created from a minimal configuration</description>
<!-- Path to the executable, which should be started -->
<executable>java</executable>
<arguments>-jar demo.jar</arguments>
</service>
如果是执行nginx.exe
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>nginx server</id>
<!-- Display name of the service -->
<name>my nginx server</name>
<!-- Service description -->
<description>This service is a service created from a minimal configuration</description>
<!-- Path to the executable, which should be started -->
<executable>nginx.exe</executable>
</service>
在winsw.exe路径下打开cmd 执行winsw.exe install 制作服务,winsw.exe uninstall 卸载服务