把Spring boot jar作为Windows服务运行
把Spring boot jar作为Windows服务运行
当你用Spring boot时,通过Java -jar就可以启动,但你不能每次开机都这样执行一遍吧?特别是当你把jar包发布给客户的时候,你总不能要求客户每次开机后都手动执行启动。所以,最好的方式就是作为服务,随机器开机启动。
Java Service Wrapper
本文就讲一讲如何把Spring boot做成服务。
笔者最先研究了JavaService,下载地址为:http://forge.ow2.org/projects/javaservice/,按照文档即可配置,比较简单,但是在执行.bat脚本文件的时候需要具有管理员权限才能安装服务,考虑到客户可能存在较难获取管理员权限的情况,遂放弃。
考虑使用Java Service Wrapper,Java Service Wrapper就轻松而简单的为我们解决了这些问题。"Java Service Wrapper"顾名思义,将我们的Java程序包装成系统服务,这样就可以随着系统的运行而自动运行,当然Java Service Wrapper(下面简称Wrapper)的功能绝不仅于此。
以下是官方给出的一些Wrapper的优点:
(1) 使用我们的产品无须在你的程序中添加任何额外的代码。
(2) 当你的程序或JVM出现问题时会自动响应事先定制的策略。
(3) 当出现问题时会及时进行通知。
(4) 完善的日志记录功能可以更好为您提供支持。
(5) 在不同的系统上你可以指定一个标准的流程相同流程,也就是说相同的程序可以不必修改即运行于不同系统。
(6) 可以将你的应用安装成windows或unix的服务或守护进程。
Java Service Wrapper下载
下载地址为 https://wrapper.tanukisoftware.com/doc/english/download.jsp,最新版本为3.5.34,根据自己的情况选择自己对应的操作系统和位数。
通过下载页面我们可以看到Wrapper几乎支持所有的系统环境,Windows32位社区版是免费使用的,Windows 64位没有免费版本。我们这里主要讲Windows系统。
Java Service Wrapper主要目录
解压后的文件目录如下图:
这些目录并不是你做服务必须的,有些可以不不要。各目录的主要作用如下:
1. bin目录下主要的文件有:InstallTestWrapper-NT.bat、TestWrapper.bat、UninstallTestWrapper-NT.bat、wrapper.exe
2. conf目录下主要文件有:wrapper.conf
3. lib目录下主要文件有:wrapper.dll、wrapper.jar、wrappertest.jar
4. logs目录下主要文件有:wrapper.log(可以配置改名的)
Java Service Wrapper配置
然后,将你的jar包放入lib目录,接下来是对conf/wrapper.conf进行修改,这是最重要的修改,直接关系到你的服务是否能创建成功。内容如下:
#encoding=UTF-8
# Configuration files must begin with a line specifying the encoding
# of the the file.
#********************************************************************
# Wrapper License Properties (Ignored by Community Edition)
#********************************************************************
# Professional and Standard Editions of the Wrapper require a valid
# License Key to start. Licenses can be purchased or a trial license
# requested on the followingpages:
# http://wrapper.tanukisoftware.com/purchase
# http://wrapper.tanukisoftware.com/trial
# Include file problems can be debugged by leaving only one '#'
# at the beginning of thefollowing line:
##include.debug
# The Wrapper will look for either of the following optional filesfor a
# valid License Key. License Key properties can optionally beincluded
# directly in thisconfiguration file.
#include ../conf/wrapper-license.conf
#include ../conf/wrapper-license-%WRAPPER_HOST_NAME%.conf
# The following property will output information about which LicenseKey(s)
# are being found, and canaid in resolving any licensing problems.
#wrapper.license.debug=TRUE
#********************************************************************
# Wrapper Localization
#********************************************************************
# Specify the language and locale which the Wrapper should use.
#wrapper.lang=en_US # en_US or ja_JP
# Specify the location of the language resource files (*.mo).
wrapper.lang.folder=../lang
#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
# Locate the java binary onthe system PATH:
wrapper.java.command=java
# Specify a specific javabinary:
#set.JAVA_HOME=/java/path
#wrapper.java.command=%JAVA_HOME%/bin/java
wrapper.java.command=../lib/jre/bin/java
# Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO
# Java Main class. This classmust implement the WrapperListener interface
# or guarantee that theWrapperManager class is initialized. Helper
# classes are provided to dothis for you.
# See the following page fordetails:
# http://wrapper.tanukisoftware.com/doc/english/integrate.html
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/这里是你自己的jar包名称
wrapper.java.classpath.2=../lib/wrapper.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
# Java Bits. On applicableplatforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE
# Java Additional Parameters
wrapper.java.additional.1=
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
# Application parameters. Addparameters as needed starting from 1
#这里很重要,这是Spring boot启动的入口
wrapper.app.parameter.1=org.springframework.boot.loader.JarLauncher
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Enables Debug output from the Wrapper.
# wrapper.debug=TRUE
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging.
wrapper.logfile=../logs/wrapper.log 日志的位置和名称
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size isspecified in bytes. The default value
# of 0, disables logrolling. May abbreviate with the 'k'(kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0
# Maximum number of rolled log files which will be allowed beforeold
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper General Properties
#********************************************************************
# Allow for the use of non-contiguous numbered properties
wrapper.ignore_sequence_gaps=TRUE
# Do not start if the pid file already exists.
wrapper.pidfile.strict=TRUE
# Title to use when running as a console
wrapper.console.title=@app.long.name@
#********************************************************************
# Wrapper JVM Checks
#********************************************************************
# Detect DeadLocked Threads in the JVM. (Requires Standard Edition)
wrapper.check.deadlock=TRUE
wrapper.check.deadlock.interval=60
wrapper.check.deadlock.action=RESTART
wrapper.check.deadlock.output=FULL
# Out Of Memory detection.
# Ignore -verbose:classoutput to avoid false positives.
wrapper.filter.trigger.1000=[Loaded java.lang.OutOfMemoryError
wrapper.filter.action.1000=NONE
# (Simple match)
wrapper.filter.trigger.1001=java.lang.OutOfMemoryError
# (Only match text in stack traces if -XX:+PrintClassHistogram isbeing used.)
#wrapper.filter.trigger.1001=Exception in thread "*"java.lang.OutOfMemoryError
#wrapper.filter.allow_wildcards.1001=TRUE
wrapper.filter.action.1001=RESTART
wrapper.filter.message.1001=The JVM has run out of memory.
#********************************************************************
# Wrapper Email Notifications. (Requires Professional Edition)
#********************************************************************
# Common Event Email settings.
#wrapper.event.default.email.debug=TRUE
#wrapper.event.default.email.smtp.host=<SMTP_Host>
#wrapper.event.default.email.smtp.port=25
#wrapper.event.default.email.subject=[%WRAPPER_HOSTNAME%:%WRAPPER_NAME%:%WRAPPER_EVENT_NAME%]Event Notification
#wrapper.event.default.email.sender=<Sender email>
#wrapper.event.default.email.recipient=<Recipient email>
# Configure the log attached to event emails.
#wrapper.event.default.email.maillog=ATTACHMENT
#wrapper.event.default.email.maillog.lines=50
#wrapper.event.default.email.maillog.format=LPTM
#wrapper.event.default.email.maillog.loglevel=INFO
# Enable specific event emails.
#wrapper.event.wrapper_start.email=TRUE
#wrapper.event.jvm_prelaunch.email=TRUE
#wrapper.event.jvm_start.email=TRUE
#wrapper.event.jvm_started.email=TRUE
#wrapper.event.jvm_deadlock.email=TRUE
#wrapper.event.jvm_stop.email=TRUE
#wrapper.event.jvm_stopped.email=TRUE
#wrapper.event.jvm_restart.email=TRUE
#wrapper.event.jvm_failed_invocation.email=TRUE
#wrapper.event.jvm_max_failed_invocations.email=TRUE
#wrapper.event.jvm_kill.email=TRUE
#wrapper.event.jvm_killed.email=TRUE
#wrapper.event.jvm_unexpected_exit.email=TRUE
#wrapper.event.wrapper_stop.email=TRUE
# Specify custom mail content
wrapper.event.jvm_restart.email.body=The JVM wasrestarted.\n\nPlease check on its status.\n
#********************************************************************
# Wrapper Windows Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when anapplication
# using this configurationfile has been installed as a service.
# Please uninstall theservice before modifying this section. The
# service can then bereinstalled.
# Name of the service
wrapper.name=这里是你的服务的名字
# Display name of the service
wrapper.displayname=这里是你的服务显示的名称
# Description of the service
wrapper.description=这里是你的服务的描述
# Service dependencies. Adddependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_START
#这里是服务的启动方式
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop (Windows NT/2000/XPonly).
wrapper.ntservice.interactive=FALSE
其他地方可以根据自己的情况决定是否要配置,至此,已经配置完毕。运行InstallTestWrapper-NT.bat(也可以修改为自己应用的名字)即可安装服务。
把Spring boot jar作为Windows服务运行相关推荐
- tomcat xjar 加密_XJar Spring Boot JAR 安全加密运行工具
GitHub: https://github.com/core-lib/xjar Spring Boot JAR 安全加密运行工具, 同时支持的原生JAR. 基于对JAR包内资源的加密以及拓展Clas ...
- Micronaut for Spring支持Spring Boot应用以Micronaut形式运行
在Micronaut 1.0.1小版本发布的同时,Object Computing, Inc.(OCI)还发布了Micronaut for Spring 1.0 M1.在发布说明中这样写到: Micr ...
- 使用Spring Boot构建REST Web服务
本教程提供了有关如何使用Spring Boot构建Restfull Web服务的分步指南. 先决条件: Eclipse IDE(最新版本) Maven的4 Java 1.8 1.创建Maven Web ...
- Spring Boot 构建RESTful Web服务
Spring Boot 构建RESTful Web服务 本指南将引导您完成使用Spring 创建" Hello World" RESTful Web服务的过程. 你会建立什么 您将 ...
- Spring Boot+gRPC构建微服务并部署到Istio(详细教程)
点击关注公众号,实用技术文章及时了解 作为Service Mesh和云原生技术的忠实拥护者,我却一直没有开发过Service Mesh的应用.正好最近受够了Spring Cloud的"折磨& ...
- Spring Boot jar 启动时设置环境参数
文章目录 1 摘要 2 核心代码 2.1 spring Boot 多环境配置 2.2 spring Boot 项目启动命令 3 Spring boot 简易启动与停止 shell 脚本 3.1 启动脚 ...
- 硬核艿艿,新鲜出炉,直接带你弄懂 Spring Boot Jar 启动原理!
" 摘要: 原创出处 http://www.iocoder.cn/Spring-Boot/jar/ 「芋道源码」欢迎转载,保留摘要,谢谢! 1. 概述 2. MANIFEST.MF 3. J ...
- .NET Worker Service 作为 Windows 服务运行及优雅退出改进
上一篇文章我们了解了如何为 Worker Service 添加 Serilog 日志记录,今天我接着介绍一下如何将 Worker Service 作为 Windows 服务运行. 我曾经在前面一篇文章 ...
- 基于spring boot的邮件微服务消息中间件设计与实现 毕业论文+系统功能图v1.0.vsdx+项目源码
下载地址:https://download.csdn.net/download/m0_63680064/36065411 项目介绍: 基于spring boot的邮件微服务消息中间件设计与实现 毕业论 ...
- 五分钟学会 Spring Boot Admin:微服务应用监控(小白必看,一看就会教程)
Spring Boot Admin:微服务应用监控 Spring Boot Admin 简介 监控信息演示 结合注册中心使用 功能演示 添加登录认证 文末福利 Spring Boot Admin 可以 ...
最新文章
- 如何去掉latex中默认显示的日期
- 总结一下这几天操作符的学习心得
- 成功解决urllib.error.URLError urlopen error Errno 11004 getaddrinfo failed
- Windbg学习 (0x0007) 命令-会话控制
- 玩转SSRS第六篇---客户端报表进阶
- 存储mysql数据存在特殊字符时处理_SQL数据库对于保存特殊字符的解决办法
- OpenGL ES和EGL关系(二十五)
- 第3章第1讲算法与流程图
- 【原】 OPenCV学习笔记1:imread()
- 关于CAN APE的使用一些记录
- 虚幻4引擎开发的手游_掌上视觉进化,盘点近年虚幻4引擎开发的手游大作
- 神经影像研究驱动的脑龄估计作为脑疾病和健康状况识别的生物学标记
- JavaRSAJS加密解密(整合版,仅供自己参考)
- Window下,C++ 操作 Mysql、Url、utf-8文件 编码问题(读取和写入)
- linux speedtest-cli测速报错
- 操作系统第6次实验报告:使用信号
- 中国地址英文翻译,英文网站注册
- CentOS7安装部署Slurm集群详细步骤及常见的问题.
- 新松机器人BG总裁高峰_曲道奎总裁出席2019中国国际机器人与智能制造发展高峰论坛 新松荣获“金手指奖”...
- 阿里巴巴开源项目: 基于mysql数据库binlog的增量订阅amp;消费
热门文章
- 如何编译CWM Recovery
- php wind8.5,PHPWind 8.5 正式版源码下载
- 博文视点“阿里云全系列技术图书”隆重亮相2021云栖大会
- 互联网专用计算机屏保,18个Windows 98屏保,简直怀念!
- Windows系统镜像下载
- 龙骨导出html文件打不开,一种用于铝型材与龙骨的连接结构的连接件的制作方法...
- ADODB.Stream
- Android 开机底层优化
- Scrapy爬取起点中文网小说信息 绝对领域cosplay
- linux系统怎么启动u盘启动盘,如何制作 linux 系统 U盘启动盘