Java Service Wrapper 部署spring boot为windows服务

前言

本文介绍下在windows上部署java web 项目,将web项目注册成web服务,这里用到了Java Service Wrapper.

下载:https://www.krenger.ch/blog/java-service-wrapper-3-5-14-for-windows-x64/

开始

步骤1:创建文件夹

新建文件夹DemoService,在DemoService文件夹下新建文件夹bin,conf,lib,logs文件夹

步骤2:复制文件

将下载的Wrapper中文件复制到DemoService中

bin:

Wrapper/src/bin/App.bat.in -------> DemoService/bin

Wrapper/src/bin/InstallApp-NT.bat.in -------> DemoService/bin

Wrapper/src/bin/UninstallApp-NT.bat.in -------> DemoService/bin

Wrapper/bin/wrapper.exe -------> DemoService/bin

conf:

Wrapper/src/conf/wrapper.conf.in -------> DemoService/conf

lib:

Wrapper/lib/wrapper.dll -------> DemoService/lib

Wrapper/lib/wrapper.jar -------> DemoService/lib

复制过去后把.in后缀去掉

步骤3: 打包spring boot项目

Java Service Wrapper 部署spring boot为windows服务

步骤4: copy到DemoService的bin目录下

Java Service Wrapper 部署spring boot为windows服务

步骤5: 修改配置文件

需要修改的:

# java路径,可以是%JAVA_HOME%/bin/java,也可以直接写路径:D://xxxx/bin/java
#wrapper.java.command=%JAVA_HOME%/bin/java

# 上面复制的wrapper.jar的路径
wrapper.java.classpath.1=../lib/wrapper.jar

# 你的java项目配置文件路径,注意后面有个点
wrapper.java.classpath.2=../bin/config/.

# 你的项目所在的路径
wrapper.java.classpath.3=../bin/.

# 你的项目
wrapper.java.classpath.4=../bin/backend.jar

# Jvm 启动时带的额外的参数
wrapper.java.additional.1= -Dfile.encoding=UTF-8

# 初始Java堆大小(以MB为单位)
wrapper.java.initmemory=3

# 最大Java堆大小(以MB为单位)
wrapper.java.maxmemory=64

# 应用参数。从1开始添加参数, (springboot主程序类)
wrapper.app.parameter.1=com.summit.MainAction

# 控制台运行时使用的标题
wrapper.console.title=test

# 服务名称
wrapper.name=DemoApp

# 显示服务的名称
wrapper.displayname=DemoApp

# 服务描述
wrapper.description=测试web项目

以下关于项目路径的配置并不固定,取决你自己放的位置

# 你的java项目配置文件路径,注意后面有个点
wrapper.java.classpath.2=../bin/config/.

# 你的项目所在的路径
wrapper.java.classpath.3=../bin/.

# 你的项目
wrapper.java.classpath.4=../bin/backend.jar

配置完后整体时这样的

#encoding=UTF-8
# Configuration files must begin with a line specifying the encoding
#  of the the file.

#********************************************************************
# Wrapper Localization
#********************************************************************
# Specify the language and locale which the Wrapper should use.
#wrapper.lang=en_US # en_US or ja_JP

# 指定语言资源文件的位置(*.mo)。
wrapper.lang.folder=../lang

#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
#  Locate the java binary on the system PATH:
wrapper.java.command=%JAVA_HOME%\bin\java
#  Specify a specific java binary:
#set.JAVA_HOME=/java/path
# java路径,可以是%JAVA_HOME%/bin/java,也可以直接写路径:D://xxxx/bin/java
#wrapper.java.command=%JAVA_HOME%/bin/java

# Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO

# Java Main class.  This class must implement the WrapperListener interface
#  or guarantee that the WrapperManager class is initialized.  Helper
#  classes are provided to do this for you.
#  See the following page for details:
#  http://wrapper.tanukisoftware.com/doc/english/integrate.html
#  一般不用动
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

# 缺少Java类路径条目的通知的日志级别。
wrapper.java.classpath.missing.loglevel=WARN

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1

# 上面复制的wrapper.jar的路径
wrapper.java.classpath.1=../lib/wrapper.jar

# 你的java项目配置文件路径,注意后面有个点
wrapper.java.classpath.2=../bin/config/.

# 你的项目所在的路径
wrapper.java.classpath.3=../bin/.

# 你的项目
wrapper.java.classpath.4=../bin/backend.jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib

# Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE

# Jvm 启动时带的额外的参数
wrapper.java.additional.1= -Dfile.encoding=UTF-8

# 初始Java堆大小(以MB为单位)
wrapper.java.initmemory=3

# 最大Java堆大小(以MB为单位)
wrapper.java.maxmemory=64

# 应用参数。从1开始添加参数, (springboot主程序类)
wrapper.app.parameter.1=com.summit.MainAction

#********************************************************************
# 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

# wrapper日志存放路径,上面新建的logs文件夹
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 is specified in bytes.  The default value
#  of 0, disables log rolling.  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 before old
#  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

# 控制台运行时使用的标题
wrapper.console.title=test

#********************************************************************
# 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:class output 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 is being 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 was restarted.\n\nPlease check on its status.\n

#********************************************************************
# Wrapper Windows Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
#  using this configuration file has been installed as a service.
#  Please uninstall the service before modifying this section.  The
#  service can then be reinstalled.

# 服务名称
wrapper.name=DemoApp

# 显示服务的名称
wrapper.displayname=DemoApp

# 服务描述
wrapper.description=测试web项目

# Service dependencies.  Add dependencies 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/XP only).
wrapper.ntservice.interactive=FALSE

# Allow the current user to perform certain actions without being prompted for
#  administrator credentials. (Requires Professional Edition)
#wrapper.ntservice.permissions.1.account=CURRENT_USER
#wrapper.ntservice.permissions.1.allow=START, STOP, PAUSE_RESUME

步骤6: 测试服务

运行App.bat如果运行正常,就可以安装服务了

步骤7: 安装服务

运行InstallApp-NT.bat安装服务
Java Service Wrapper 部署spring boot为windows服务

安装完成之后就可以在服务中看见了
Java Service Wrapper 部署spring boot为windows服务

右键服务启动就可以了

步骤8: 卸载服务

运行UninstallApp-NT.bat就ok了

结语

本次测试很顺利,没遇到问题,如果有人在操作过程中踩坑,欢迎分享到评论区。

上一篇:Python中使用MongoEngine1


下一篇:总结CSS3新特性(Animation篇)