1、在idea中用maven将程序打成jar,放到运行的目录中。配置文件夹也要放进来
2、去github上面下载winsw: https://github.com/kohsuke/winsw/releases (只需要下载WinSW.NET4.exe)
3、新建xml文件
<configuration>
<id>srv308</id>
<name>srv308</name>
<description>srv308</description>
<!-- java环境变量 -->
<env name="JAVA_HOME" value="%JAVA_HOME%"/>
<executable>java</executable>
<arguments>-jar “d:\jar2Service\srv308.jar”</arguments>
<!-- 开机启动 -->
<startmode>Automatic</startmode>
<!-- 日志配置 -->
<logpath>%BASE%\log</logpath>
<logmode>rotate</logmode>
</configuration>
4、将WinSW.NET4.exe重命名成跟你的java服务名一样,注意java服务名尽量不要用“.”和汉字
5、命令行定位到当前目录,执行:
srv308.exe install
这样我们服务就可以实现开机自启了 并且也不会再有运行框。更新服务的话 暂停服务 替换jar包 重启服务就好
6、卸载服务:
执行”sc delete 服务名称“ 注意在管理员身份运行