Java wrapper打包springboot项目到linux和Windows
1 Java wrapper 说明
前提: 一定要有Java环境(我使用的是jdk1.8)
可以直接去看官方的网站查看详情配置
官方网站的地址: https://wrapper.tanukisoftware.com/doc/english/home.html
下载:linux的目前免费的 windows 64位的好像收费的
下载一个社区版本的应该就够用了
2 linux的安装步骤
2.1 解压 创建目录
如果觉得嫌麻烦 就是直接在windows上操作 然后完成了以后直接打包上传到linux
解压的目录,然后我们新建自己的项目目录java-jsw
2.2 复制文件
前面是你解压的原文件 后边是你自己建的目录路径
cp $(WRAPPER_HOME)/bin/wrapper $(EXAMPLE_HOME)/bin/wrapper
cp $(WRAPPER_HOME)/lib/wrapper.jar $(EXAMPLE_HOME)/lib/wrapper.jar
cp $(WRAPPER_HOME)/lib/libwrapper.so $(EXAMPLE_HOME)/lib/libwrapper.so
cp $(WRAPPER_HOME)/src/bin/App.sh.in $(EXAMPLE_HOME)/bin/helloworldserver
cp $(WRAPPER_HOME)/src/conf/wrapper.conf.in $(EXAMPLE_HOME)/conf/wrapper.conf
#这个是启动文件
cp $(WRAPPER_HOME)/src/bin/App.sh.in $(EXAMPLE_HOME)/bin/helloworldserver
#给启动文件授权
chmod +x helloworldserver
自己的springboot项目(java代码)
2.3 配置文件
warpper.conf 修改的部分
wrapper.lang.folder=../lang
wrapper.jarfile=../lib/wrapper.jar
#java的路径
wrapper.java.command=/opt/jdk1.8.0_144/bin/java
#java的路径 如果安装了并配置了环境变量 就可以用这个默认的
wrapper.java.command=%JAVA_HOME%/bin/java
# 默认的这个不要改
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
wrapper.java.classpath.missing.loglevel=WARN
# 运行所需要的jar wrapper.jar是固定的 然后springboot的classes文件 最后是需要的jar文件
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/classes
wrapper.java.classpath.3=../lib/*.jar
wrapper.java.library.path.1=../lib
wrapper.java.additional.auto_bits=TRUE
wrapper.java.additional.1=
#启动类的全路径类名
wrapper.app.parameter.1=com.hexin.file.sync.HexinFilesyncApplication
#日志按天输出
wrapper.logfile=../logs/run-YYYYMMDD.log
2.4 启动
把编辑好的文件打包到linux上边
测试运行的命令
所有命令
[root@yang154 bin]# ./app
Usage: ./app [ console | start | stop | restart | condrestart | status | install | installstart | remove | dump ]
Commands:
console Launch in the current console.
start Start in the background as a daemon process.
stop Stop if running as a daemon or in another console.
restart Stop if running and then start.
condrestart Restart only if already running.
status Query the current status.
install Install to start automatically when system boots.
installstart Install and start running as a daemon process.
remove Uninstall.
dump Request a Java thread dump if running.
测试
[root@yang154 bin]# ./app console
项目运行起来了就算成功
安装并启动
[root@yang154 bin]# ./app installstart
表示成功 这个时候就可以访问了
停止
[root@yang154 bin]# ./app stop
重启
[root@yang154 bin]# ./app restart
3 windows
百度的一个windows的下载地址:点击跳转
官方的配置地址 https://wrapper.tanukisoftware.com/doc/english/qna-service.html
步骤和上面的一样 不过复制的文件不一样
3.1 配置文件
#encoding=UTF-8
# Configuration files must begin with a line specifying the encoding
# of the the file.
#
# NOTE - Please use src/conf/wrapper.conf.in as a template for your
# own application rather than the values used for the
# TestWrapper sample.
#********************************************************************
# 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 following pages:
# http://wrapper.tanukisoftware.com/purchase
# http://wrapper.tanukisoftware.com/trial
# Include file problems can be debugged by leaving only one '#'
# at the beginning of the following line:
##include.debug
# The Wrapper will look for either of the following optional files for a
# valid License Key. License Key properties can optionally be included
# directly in this configuration file.
#include ../conf/wrapper-license.conf
#include ../conf/wrapper-license-%WRAPPER_HOST_NAME%.conf
# The following property will output information about which License Key(s)
# are being found, and can aid 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
#********************************************************************
# Wrapper Jar file
wrapper.jarfile=../lib/wrapper.jar
# Java Application
# Locate the java binary on the system PATH:
wrapper.java.command=java
# Specify a specific java binary:
#set.JAVA_HOME=/java/path
#wrapper.java.command=%JAVA_HOME%/bin/java
wrapper.java.command=../jre/bin/javaw.exe
# 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
# Log level for notices about missing Java Classpath entries.
wrapper.java.classpath.missing.loglevel=WARN
# Java Classpath. Add class path elements as needed starting from 1
wrapper.java.classpath.1=../lib/classes
wrapper.java.classpath.2=../lib/wrapper.jar
wrapper.java.classpath.3=../lib/*.jar
# Java Modulepath. (Requires Java 9 or above)
# Add module path elements as needed starting from 1
wrapper.java.library.path.1=../lib
# Java Module list. (Requires Java 9 or above)
# Add module names as needed starting from 1
#wrapper.java.module.1=
# 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
wrapper.app.parameter.1=com.hexin.file.sync.HexinFilesyncApplication
#********************************************************************
# 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
wrapper.logfile=../logs/run-YYYYMMDD.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
# Roll mode of the log file.
# SIZE_OR_WRAPPER causes the file to be rolled whenever its size exceeds the
# value defined by wrapper.logfile.maxsize, or whenever the Wrapper is
# launched.
wrapper.logfile.rollmode=SIZE_OR_WRAPPER
# 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=10m
# 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=9
# 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=Test Wrapper Sample Application
#********************************************************************
# Wrapper JVM Checks
#********************************************************************
# 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.
#********************************************************************
# 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.
# Name of the service
wrapper.name=sync
# Display name of the service
wrapper.displayname=sync
# Description of the service
wrapper.description=sync service
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed.
# AUTO_START, DELAY_START (Requires Standard Edition) 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
3.2 复制文件
上图文件复制的地方 全部复制过去 保留自己需要的 然后去掉后缀.in
wapper.exe文件
测试启动就是点击App.bat 就会有信息的输出 installApp就是注册为一个windows上的一个服务
需要注意的点 有Java环境
wrapper.java.command=../jre/bin/javaw.exe
我这样配置是我把Java安装时候jre目录复制到了这个目录下
3.3 启动
双击App.bat
结束就是ctrl+c
注册成服务以后