(1)环境,电脑需要安装Microsoft.NETFramework 4 ,如果有的话这个可以不安装
下载地址:
https://download.microsoft.com/download/1/B/E/1BE39E79-7E39-46A3-96FF-047F95396215/dotNetFx40_Full_setup.exe
(2)我们采用WinSW,用了不少,发现就这个最好用
下载地址:
https://github.com/winsw/winsw/releases
下载他的exe和xml配置文件,两个下载下来后需要同目录,同文件名
然后将exe和xml放在同一个目录下,并且重命名为一样的名字,如aaa.exe 和aaa.xml
把jar包做成服务
编辑xml文件:
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>aaa</id>
<!-- Display name of the service -->
<name>aaa</name>
<!-- Service description -->
<description>ceshi</description>
<executable>java</executable>
<arguments>-jar aaa.jar</arguments>
<logpath>D:\aaa\\testlog\</logpath>
</service>
id:唯一标识,我设为jar包的名称
name:服务中展示的名字
description:服务描述
executable:java 或 jdk路径
arguments:执行的命令,我这因为jar包和xml在一个目录,可以直接写jar包名
logpath:日志输出指定位置
把nginx做成服务
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>nginx</id>
<!-- Display name of the service -->
<name>nginx</name>
<!-- Service description -->
<description>nginx</description>
<!-- Path to the executable, which should be started -->
<executable>nginx.exe</executable>
<logpath>D:\aaa\pacspoj\nginx-1.22.0\testlog\</logpath>
</service>
id:唯一标识,我设为jar包的名称
name:服务中展示的名字
description:服务描述
executable:nginx执行命令
logpath:日志输出指定位置
在xxx.exe当前目录中进入cmd ,执行xxx.exe install,服务中就有了
也可以把install这些做成.bat脚本:
如:install.bat文件,安装服务,.bat内容如下,路径\xxx.exe install(如果在本目录下不用加路径)
安装服务
xxx.exe install
重启服务
xxx.exe restart
停止服务
xxx.exe stop
卸载服务
xxx.exe uninstall