日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

把Spring boot jar作为Windows服务运行

發(fā)布時(shí)間:2023/12/20 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 把Spring boot jar作为Windows服务运行 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

把Spring boot jar作為Windows服務(wù)運(yùn)行


當(dāng)你用Spring boot時(shí),通過Java -jar就可以啟動(dòng),但你不能每次開機(jī)都這樣執(zhí)行一遍吧?特別是當(dāng)你把jar包發(fā)布給客戶的時(shí)候,你總不能要求客戶每次開機(jī)后都手動(dòng)執(zhí)行啟動(dòng)。所以,最好的方式就是作為服務(wù),隨機(jī)器開機(jī)啟動(dòng)。

Java Service Wrapper

本文就講一講如何把Spring boot做成服務(wù)。

筆者最先研究了JavaService,下載地址為:http://forge.ow2.org/projects/javaservice/,按照文檔即可配置,比較簡(jiǎn)單,但是在執(zhí)行.bat腳本文件的時(shí)候需要具有管理員權(quán)限才能安裝服務(wù),考慮到客戶可能存在較難獲取管理員權(quán)限的情況,遂放棄。

考慮使用Java Service Wrapper,Java Service Wrapper就輕松而簡(jiǎn)單的為我們解決了這些問題。"Java Service Wrapper"顧名思義,將我們的Java程序包裝成系統(tǒng)服務(wù),這樣就可以隨著系統(tǒng)的運(yùn)行而自動(dòng)運(yùn)行,當(dāng)然Java Service Wrapper(下面簡(jiǎn)稱Wrapper)的功能絕不僅于此。

??????? 以下是官方給出的一些Wrapper的優(yōu)點(diǎn):

??????? (1) 使用我們的產(chǎn)品無須在你的程序中添加任何額外的代碼。
??????? (2)
當(dāng)你的程序或JVM出現(xiàn)問題時(shí)會(huì)自動(dòng)響應(yīng)事先定制的策略。
??????? (3)
當(dāng)出現(xiàn)問題時(shí)會(huì)及時(shí)進(jìn)行通知。
??????? (4)
完善的日志記錄功能可以更好為您提供支持。
??????? (5)
在不同的系統(tǒng)上你可以指定一個(gè)標(biāo)準(zhǔn)的流程相同流程,也就是說相同的程序可以不必修改即運(yùn)行于不同系統(tǒng)。
??????? (6)
可以將你的應(yīng)用安裝成windowsunix的服務(wù)或守護(hù)進(jìn)程。

Java Service Wrapper下載

下載地址為 https://wrapper.tanukisoftware.com/doc/english/download.jsp,最新版本為3.5.34,根據(jù)自己的情況選擇自己對(duì)應(yīng)的操作系統(tǒng)和位數(shù)。

通過下載頁面我們可以看到Wrapper幾乎支持所有的系統(tǒng)環(huán)境,Windows32位社區(qū)版是免費(fèi)使用的,Windows 64位沒有免費(fèi)版本。我們這里主要講Windows系統(tǒng)。

Java Service Wrapper主要目錄

解壓后的文件目錄如下圖:

這些目錄并不是你做服務(wù)必須的,有些可以不不要。各目錄的主要作用如下:

?

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目錄,接下來是對(duì)conf/wrapper.conf進(jìn)行修改,這是最重要的修改,直接關(guān)系到你的服務(wù)是否能創(chuàng)建成功。內(nèi)容如下:

?

#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啟動(dòng)的入口

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=這里是你的服務(wù)的名字

?

# Display name of the service

wrapper.displayname=這里是你的服務(wù)顯示的名稱

?

# Description of the service

wrapper.description=這里是你的服務(wù)的描述

?

# 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

#這里是服務(wù)的啟動(dòng)方式

wrapper.ntservice.starttype=AUTO_START

?

# Allow the service to interact with the desktop (Windows NT/2000/XPonly).

wrapper.ntservice.interactive=FALSE

?

?

?

其他地方可以根據(jù)自己的情況決定是否要配置,至此,已經(jīng)配置完畢。運(yùn)行InstallTestWrapper-NT.bat(也可以修改為自己應(yīng)用的名字)即可安裝服務(wù)。

總結(jié)

以上是生活随笔為你收集整理的把Spring boot jar作为Windows服务运行的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。