补习系列-springboot-使用assembly进行项目打包
springboot-maven插件
repackage目标声明
Requires a Maven project to be executed.
Requires dependency resolution of artifacts in scope: compile+runtime.
Since version: 1.1.
Binds by default to the lifecycle phase: package.
1. 项目打包Jar
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
如此,执行mvn package可自动生成一个独立可执行的jar文件
2. 项目完整构建
通常,项目发布时除了jar包,还会包含配置文件、启停脚本等,此时需要借助assembly插件完成重复打包
构建结构
base
- bin
- start.sh
- stop.sh
- application.properties
- log4j.properties
- app-0.0.1-SNAPSHOT.jar
pom定义
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/build/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
说明
将assembly定义在spring-boot:repackage之后,这样maven在执行package阶段时会按照声明顺序处理;
assembly.xml存放于src/main/build目录,此外用于发布的config、bin目录及文件都放到这个目录;
assembly定义
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory> <!-- disable the creation of root's distribution dir in the archive -->
<fileSets>
<!-- config files -->
<fileSet>
<directory>${basedir}/src/main/build/config</directory>
<excludes></excludes>
<includes>
<include>application*.properties</include>
<include>log4j.properties</include>
</includes>
<fileMode>0644</fileMode>
<outputDirectory>/</outputDirectory>
</fileSet>
<!-- scripts -->
<fileSet>
<directory>${basedir}/src/main/build/bin</directory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
<outputDirectory>/</outputDirectory>
</fileSet>
<!-- executable jar -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
</assembly>
3. 本地包依赖
- 定义scope=system依赖
<dependency>
<groupId>com.xxx.component</groupId>
<artifactId>mongoop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>D:\work\maven\repo\m2\xxx.jar</systemPath>
</dependency>
- 声明springboot打包时包含system范围的依赖
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
参考文档
springboot文档-maven插件使用
关于springboot-repackage
maven内置变量
补习系列-springboot-使用assembly进行项目打包的更多相关文章
- Springboot基于assembly的服务化打包
(1)首先我们编辑 assembly.xml 配置文件,在前文的基础上新增第三方依赖设置(高亮部分),实现将第三方的 jar 包添加到压缩包里的 lib 目录: <?xml version=&q ...
- SpringBoot+Maven聚合多项目打包成jar
已我最近自己在玩的一个DEMO为例 taosir为pom.xml,其他子项目均为其modules,且为jar项目 eureka为注册中心.workflow为提供者.entrance为调用方 entra ...
- springboot之多模块化项目打包
1.目录结构 2.打成war包,只需在web子项目中的pom文件中添加 <packaging>war</packaging> <build> <!-- 为ja ...
- 补习系列(1)-springboot项目基础搭建课
目录 前言 一.基础结构 二.添加代码 三.应用配置 四.日志配置 五.打包部署 小结 前言 springboot 最近火的不行,目前几乎已经是 spring 家族最耀眼的项目了.抛开微服务.技术社区 ...
- 补习系列(19)-springboot JPA + PostGreSQL
目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...
- 补习系列(18)-springboot H2 迷你数据库
目录 关于 H2 一.H2 用作本地数据库 1. 引入依赖: 2. 配置文件 3. 样例数据 二.H2 用于单元测试 1. 依赖包 2. 测试配置 3. 测试代码 小结 关于 H2 H2 数据库是一个 ...
- 补习系列(16)-springboot mongodb 数据库应用技巧
目录 一.关于 MongoDB 二.Spring-Data-Mongo 三.整合 MongoDB CRUD A. 引入框架 B. 数据库配置 C. 数据模型 D. 数据操作 E. 自定义操作 四.高级 ...
- 补习系列(17)-springboot mongodb 内嵌数据库
目录 简介 一.使用 flapdoodle.embed.mongo A. 引入依赖 B. 准备测试类 C. 完善配置 D. 启动测试 细节 二.使用Fongo A. 引入框架 B. 准备测试类 C.业 ...
- 补习系列(15)-springboot 分布式会话原理
目录 一.背景 二.SpringBoot 分布式会话 三.样例程序 四.原理进阶 A. 序列化 B. 会话代理 C. 数据老化 小结 一.背景 在 补习系列(3)-springboot 几种scope ...
随机推荐
- Simple 杂题练手记
Problem 1 世界上最可爱的珂朵莉 时间限制:C/C++ 1秒,空间限制:C/C++ 65536K 题目描述 我永远喜欢珂朵莉~! 有两个长为n的序列a[i]与b[i] 你可以把任意不多于x个a ...
- The frist email to myself by python
昨天用python模块给自己发了第一封电子邮件,真是激动 今天完善了一下. code: import smtplib from email.mime.text import MIMEText//ema ...
- iOS 上传自己的工程(模块工具类)到cocoapods上遇到坑
最近在研究把自己写的工具类和模块上传到cocoapods上, 再新构建项目中可以直接使用cocoapods使用 也可以更新之前的版本 便于维护项目. 但是在这个过程中遇到了种种问题 但是最后还是解决 ...
- sublime设置sublimeREPL-python-run current file 快捷键
弄了3个小时的快捷键,一直不能成功使用,百度上一堆一样的方法,最后FQ才找到能用的方法,真是服了. 方法: ①首选项->快捷键设置 填写如下内容: [ {"keys": [& ...
- JAVA_AesCBC纯净例子
import java.io.UnsupportedEncodingException; import java.security.InvalidAlgorithmParameterException ...
- 1.Git安装
1.安装 首先下载安装包https://git-scm.com/downloads/ 双击安装任意盘符,双击之后一路Next,当然也可以修改默认配置 安装结束!
- OpenCV常用头文件介绍
转载:https://www.cnblogs.com/wangguchao/p/7244483.html 1.OpenCV包含的模块 cv – 核心函数库 cvaux – 辅助函数库 cxcore – ...
- anaconda安装opencv(python)
1.win10 win10没有安装python,只安装了anaconda,然后使用pip安装opencv-python,版本很新,opencv_python4.0.0的. 网速有点莫名其妙,时快时慢 ...
- 设置mysql InnoDB存储引擎下取消自动提交事务
mysql 存储引擎中最长用的有两种,MyISAM 存储引擎和InnoDB存储引擎. 1.MyISAM 存储引擎 不支持事务,不支持外键,优势是访问速度快: 2.InnoDB存储引擎 支持事务,一般项 ...
- LoadRunner(三)——LR相关概念&组成部分
参考学习感谢:<精通软件性能测试与LoadRunner实战> 一.运行机制和主要组成部分 1.LoadRunner主要由VuGen.Controller和Analysis三部分构成: 2. ...