jar注册为windows服务并启动
1、服务注册工具WinSW.NET4.exe
https://github.com/kohsuke/winsw/releases
2、将exe改为ja包名称,也是服务对应的名称
3、创建服务名.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>JPA_Test-1.0-SNAPSHOT</id>
<!-- Display name of the service -->
<name>JPA_Test-1.0-SNAPSHOT</name>
<!-- Service description -->
<description>注册到win服务的JPA_Test-1.0-SNAPSHOT.jar</description>
<!-- Path to the executable, which should be started -->
<executable>java</executable>
<arguments> -server -Xms64m -Xmx128m -XX:PermSize=64M -XX:MaxPermSize=128M -jar -Dfile.encoding=UTF-8 %BASE%\JPA_Test-1.0-SNAPSHOT.jar</arguments>
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>5120</sizeThreshold>
<keepFiles>7</keepFiles>
</log>
</service>
4、创建注册并启动的脚本Install.bat
@echo off
JPA_Test-1.0-SNAPSHOT.exe install
sc start JPA_Test-1.0-SNAPSHOT
exit
并且会自动生成log启动日志文件:
5、创建停止并删除服务的脚本UnInstall.bat
@echo off
sc stop JPA_Test-1.0-SNAPSHOT
JPA_Test-1.0-SNAPSHOT.exe uninstall
exit
还没有评论,来说两句吧...