Windows Service Wrapper

版权声明:LeifChen原创,转载请注明出处,谢谢~ https://blog.csdn.net/leifchen90/article/details/85128095

Windows Service Wrapper

Windows Service Wrapper 可以将 Java 的 jar 包注册为 windows 服务。

下载

官方 GitHub下载 WinSW.NET4.exe 和 sample-minimal.xml

配置

把可执行的 jar 包和下载的 winsw 放在同一个目录下,并更改名称为一致,例如 MyApp 。

image

更改 MyApp.xml 配置文件:

<configuration>
    <id>MyApp</id>
    <name>MyApp</name>
    <description>This is MyApp.</description>
    
    <executable>java</executable>
    <arguments>-jar "%BASE%"\MyApp.jar</arguments>
    
    <logpath>%BASE%\logs</logpath>
    <log mode="roll-by-time">
    <pattern>yyyyMMdd</pattern>
    </log>
</configuration>

运行

1 注册/卸载服务

以管理员身份运行 CMD 命令窗口,输入命令就可以将 jar 注册为 windows 服务

MyApp.exe install     # 注册服务
MyApp.exe uninstall  # 卸载服务

2 启动/停止服务

在 CMD 命令窗口,输入命令启动服务,或我的电脑右键管理,在服务列表中启动服务。

MyApp.exe start     # 启动服务
MyApp.exe stop     # 停止服务
MyApp.exe restart  # 重启服务
MyApp.exe status   # 查看服务运行状态

参考

  1. 官方GitHub仓库

猜你喜欢

转载自blog.csdn.net/leifchen90/article/details/85128095
今日推荐