springboot打包上线
发布到线上的包结构
runtime是发布到线上的目录结构


1.项目pom.xml添加打包配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>sigma.resource.sync.SigmaApplication</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<useDefaultDelimiters>true</useDefaultDelimiters><!-- 这是重点-->
</configuration>
<executions>
<execution>
<id>copy-fatjar</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/build</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.${project.packaging}</include>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-bin</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/build/bin</outputDirectory>
<resources>
<resource>
<directory>src/main/bin</directory>
<include>start.sh</include>
<include>stop.sh</include>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy resource</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${basedir}/src/main</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>src/main/resources/public</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
2.创建脚本目录
src/main/bin
3.启动及停止脚本
src/main/bin/start.sh
#!/bin/bash
#----------以下变量可以在脚本中直接使用----------------
# $def_app_id 应用id
# $def_app_name 应用名称
# $def_app_domain 应用域名
# $def_app_deploy_path 兼容老部署,废弃
# $def_path_app_log 应用日志路径 如:/export/Logs/
# $def_path_app_data 如:/export/Data
# $def_group_id 分组 id
# $def_instance_id 实例id
# $def_instance_name 实例名称 server1
# $def_instance_path 实例完成路径 /export/Instances/jone/server1/
# $def_host_ip
#--------------------------
#set -o errexit
readonly APP_NAME="sigma-sync" #定义当前应用的名称
readonly JAR_VERSION="1.0-SNAPSHOT" #打包的JAR版本
#获取当前应用的进程 id
function get_pid
{
pgrep -f "$EXE_JAR"
}
BASEDIR=$(cd $(dirname $0) && pwd)/.. # 获取运行脚本的上级目录
readonly JAVA_HOME="/export/servers/jdk1.8.0_60" # java home
readonly JAVA="$JAVA_HOME/bin/java"
APP_LOG_DIR="/export/Logs/sigma-sync"
mkdir -p ${APP_LOG_DIR}
EXE_JAR="$APP_NAME-$JAR_VERSION.jar"
echo "$EXE_JAR"
# FIXME: make this configurable
OPTS_MEMORY="-Xms2G -Xmx2G -server -XX:MaxPermSize=256M -Xss256K" #定义启动 jvm 的参数信息。
CLASSPATH="$BASEDIR/"
[[ -z $(get_pid) ]] || {
echo "ERROR: $APP_NAME already running" >&2
exit 1
}
echo "Starting $APP_NAME ...."
[[ -x $JAVA ]] || {
echo "ERROR: no executable java found at $JAVA" >&2
exit 1
}
cd $BASEDIR
setsid "$JAVA" $OPTS_MEMORY -jar "$EXE_JAR" "$@" > /dev/null 2>&1 &
sleep 0.5
[[ -n $(get_pid) ]] || {
echo "ERROR: $APP_NAME failed to start" >&2
exit 1
}
echo "$APP_NAME is up runnig :)"
src/main/bin/stop.sh
#!/bin/bash
set -o errexit
set -o nounset
readonly APP_NAME="sigma-sync" #定义当前应用的名称
readonly JAR_VERSION="1.0-SNAPSHOT" #打包的JAR版本
EXE_JAR="$APP_NAME-$JAR_VERSION.jar"
#获取当前应用的进程 id
function get_running_pid
{
pgrep -f "$EXE_JAR"
}
readonly SELF_DIR=$(cd $(dirname $0) && pwd)
function stop
{
local -i timeout=20
local -i interval=1
local -r service_pid=$(get_running_pid) || true # ignore error
[[ -n $service_pid ]] || {
echo "WARNING: process not found, nothing to stop" >&2
exit 0
}
kill $service_pid
while (( timeout > 0 )) && get_running_pid > /dev/null; do
echo -n "."ƒ
sleep $interval
timeout=$(( timeout - interval ))
done
if get_running_pid > /dev/null; then
echo "WARNING: process still alive, sending SIGKILL ..." >&2
kill -9 "$service_pid"
fi
}
function main
{
get_running_pid > /dev/null || {
echo "WARNING: process not found, nothing to stop" >&2
exit 0 # Ignore error
}
stop
}
main "$@"
4.构建
mvn clean -U install -P prod -Dmaven.test.skip=true
springboot打包上线的更多相关文章
- springBoot 打包上线跳过连接数据库
在pom文件下添加 <skipTests>true</skipTests> 这一行 如下: <properties> <project.build.sourc ...
- Xcode 8 打包上线 iTunes Connect 找不到构建版本
Xcode 8 打包上线 iTunes Connect 找不到构建版本 最近苹果推出新的mac操作系统(macOS Sierra 10.12),大家可能都已经升级了,作为一个开发者,小编肯定是第一时间 ...
- springboot 打包
springboot 打包 先clean 然后 maven package 通过命令java -jar target/GoshenWepPro-0.1.0.jar运行程序
- Vuejs技术栈从CLI到打包上线实战全解析
前言 本文是自己vue项目实践中的一些总结,针对Vue2及相关技术栈,实践中版本为2.3.3. 开发前须知 vue-cli 在开发前,我们要至少通读一遍vue官方文档和API(看官方文档是最重要的,胜 ...
- 前端自动化(三) 合并压缩css、压缩js、添加时间戳、打包上线操作
前端自动化(三) 合并压缩css.压缩js.添加时间戳.打包上线操作 此文在前两篇基础上对比参考,会很方便理解 gulp.task("delete",function(){ r ...
- springboot打包不同环境配置与shell脚本部署
本篇和大家分享的是springboot打包并结合shell脚本命令部署,重点在分享一个shell程序启动工具,希望能便利工作: profiles指定不同环境的配置 maven-assembly-plu ...
- SpringBoot打包成war
关于SpringBoot打成jar包以及jar包如何在Linux持久运行,我在前面已经说过了,所以本次不再赘述. 关于SpringBoot打包成war,其实步骤特别简单,如下图所示(如果是jar,通常 ...
- vue菜鸟从业记:完成项目最后一公里之真机测试和打包上线
最近我朋友王小闰他们公司的项目开发已经进入收尾阶段,前后端并行开发的差不多了,联调也调过了,上篇文章里也讲到了,所谓联调,就仿佛在说“我也不知道我的接口文档写的对不对,我们验证一下吧?我也不知道我的数 ...
- springboot打包去除资源文件,启动时指定配置文件位置,使用log4j2替换默认logback
springboot打包时,去掉资源文件 <build> <resources> <resource> <directory>src/main/reso ...
随机推荐
- B - 真·签到题 FZU - 2214(背包)
Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the item ...
- 一文读懂eBPF/XDP
XDP概述 XDP是Linux网络路径上内核集成的数据包处理器,具有安全.可编程.高性能的特点.当网卡驱动程序收到数据包时,该处理器执行BPF程序.XDP可以在数据包进入协议栈之前就进行处理,因此具有 ...
- 拿到蚂蚁金服的offer是一种什么体验?3年Java程序员分享面经
前言:我是一名三年的Java程序员,之前一直是在外包公司工作的.在这个月五号的时候,通过我的学长做内推,有了去蚂蚁金服面试的机会.我是在12号接到的电话面试的,因为蚂蚁金服需要7天的简历评估的.还有就 ...
- hdu4876 深搜+(随机枚举剪枝)
题意: 给你n个数,让你从选择k个数,然后排成一个环(k个数的顺序随意,但是排成一个环后就不能变了),然后可以在这个环上任意的找连续w个数(w<=k),可以找多次,得到一个值等于当前 ...
- hdu4530 水题
题意: 小Q系列故事--大笨钟 Time Limit: 600/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- 路由器逆向分析------MIPS系统网络的配置(QEMU)
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/69378333 MIPS系统网络的配置 使用QEMU 模拟正在运行的MIPS系统并 ...
- 如何以最简单的方式安装 KALI 渗透测试框架系统
0x01 第一步下载 KALI 百度搜索 KALI 官网,找到下载区,我选的是 64 位标准版,但是推荐下载 32 位(功能貌似更全) 这个为下载后的 iso 镜像文件 0x02 第二步打开虚拟机,配 ...
- OpenSSL相关漏洞
目录 心脏出血漏洞(CVE-2014-0160) OpenSSL CCS注入漏洞(CVE-2014-0224) OpenSSL FREAK Attack漏洞(CVE-2015-0204) TLS/SS ...
- 线程操作与进程挂起(Windows核心编程)
0x01 线程挂起与切换 对于挂起进程,挂起线程则比较简单,利用 ResumeThread 与 SuspendThread 即可,当线挂起时线程用户状态下的一切操作都会暂停 #include < ...
- 攻防世界Web刷题记录(新手区)
攻防世界Web刷题记录(新手区) 1.ViewSource 题如其名 Fn + F12 2.get post 3.robots robots.txt是搜索引擎中访问网站的时候要查看的第一个文件.当一个 ...