SpringBoot jar 作为Wrapper服务启动-Windows

引言

同步Linux版本教程参考:SpringBoot jar包作为Wrapper服务启动-Linux
此教程为Windows上将SpringBoot jar作为服务启动, 版本:SpringBoot-2.1.2RELEASE。
该服务中web程序的context-path、port都会以SpringBoot中配置的为准。

步骤

  1. 下载Java Service Wrapper。目前最新版本为:3.5.37。选择自己对应的操作系统和位数,一般是Windows+x86 cpu。

  2. 修改conf/wrapper.conf文件,最好先备份

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    #encoding=UTF-8

    ##不知道为啥,这句去掉就不能启动服务
    #include ../conf/wrapper-license.conf

    #需要取消注释,否则会去找wrapperjni_zh.mo文件,但是../lang/中没有该文件
    <font color=red>wrapper.lang=en_US # en_US or ja_JP
    wrapper.lang.folder=../lang/</font>

    #java相关路径
    set.JAVA_HOME=D:\jdks\jdk1.8_181
    wrapper.java.command=%JAVA_HOME%/bin/java

    #老版本写法
    #wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperStartStopApp
    <font color=red>wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp</font>

    #自己的jar包路径
    <font color=red>wrapper.java.classpath.1=../lib/boot.jar
    wrapper.java.classpath.2=../lib/wrapper.jar</font>

    #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

    #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. Add parameters as needed starting from 1
    #这里很重要,这是Spring boot启动的入口
    <font color=red>wrapper.app.parameter.1=org.springframework.boot.loader.JarLauncher</font>
    #如果代码包与依赖jar包分开打包也可以直接写main所在的入口类
    #wrapper.app.parameter.1=com.ysl.springboot.SpringbootApplication

    #wrapper.console.format=PM
    wrapper.console.format=LPDTM

    #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
    #wrapper 日志
    wrapper.logfile=../logs/boot_YYYYMMDD.log
    wrapper.logfile.rollmode=DATE

    #Format of output for the log file. (See docs for formats)
    #wrapper.logfile.format=LPTM
    wrapper.logfile.format=LPDTM

    #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

    #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=Test boot-Application

    #Detect DeadLocked Threads in the JVM. (Requires Standard Edition)
    wrapper.check.deadlock=TRUE
    wrapper.check.deadlock.interval=10
    wrapper.check.deadlock.action=RESTART
    wrapper.check.deadlock.output=FULL

    #Out Of Memory detection.
    #(Ignore output from dumping the configuration to the console. This is only needed by the TestWrapper sample application.)
    wrapper.filter.trigger.999=wrapper.filter.trigger.*java.lang.OutOfMemoryError
    wrapper.filter.allow_wildcards.999=TRUE
    wrapper.filter.action.999=NONE
    #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.

    #Specify custom mail content
    wrapper.event.jvm_restart.email.body=The JVM was restarted.\n\nPlease check on its status.\n

    #Name of the service
    #这里是你的服务的名字
    <font color=red>wrapper.name=wrapper-boot</font>

    #Display name of the service
    #这里是你的服务显示的名称
    <font color=red>wrapper.displayname=boot-Application</font>

    #Description of the service
    #这里是你的服务的描述
    <font color=red>wrapper.description=boot-Application Description</font>

    #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

    wrapper.ping.timeout=120
  3. 双击运行bin/InstallTestWrapper-NT.bat,然后ctrl+alt+del查看服务是否安装成功。找到自己的服务右键启动即可。

说在最后的话

服务不是免费的


参考
https://blog.csdn.net/myvernal/article/details/79104026
https://my.oschina.net/u/3866531/blog/1845669/
https://blog.csdn.net/sq287197314/article/details/82996012

评论