springboot-maven插件

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进行项目打包的更多相关文章

  1. Springboot基于assembly的服务化打包

    (1)首先我们编辑 assembly.xml 配置文件,在前文的基础上新增第三方依赖设置(高亮部分),实现将第三方的 jar 包添加到压缩包里的 lib 目录: <?xml version=&q ...

  2. SpringBoot+Maven聚合多项目打包成jar

    已我最近自己在玩的一个DEMO为例 taosir为pom.xml,其他子项目均为其modules,且为jar项目 eureka为注册中心.workflow为提供者.entrance为调用方 entra ...

  3. springboot之多模块化项目打包

    1.目录结构 2.打成war包,只需在web子项目中的pom文件中添加 <packaging>war</packaging> <build> <!-- 为ja ...

  4. 补习系列(1)-springboot项目基础搭建课

    目录 前言 一.基础结构 二.添加代码 三.应用配置 四.日志配置 五.打包部署 小结 前言 springboot 最近火的不行,目前几乎已经是 spring 家族最耀眼的项目了.抛开微服务.技术社区 ...

  5. 补习系列(19)-springboot JPA + PostGreSQL

    目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...

  6. 补习系列(18)-springboot H2 迷你数据库

    目录 关于 H2 一.H2 用作本地数据库 1. 引入依赖: 2. 配置文件 3. 样例数据 二.H2 用于单元测试 1. 依赖包 2. 测试配置 3. 测试代码 小结 关于 H2 H2 数据库是一个 ...

  7. 补习系列(16)-springboot mongodb 数据库应用技巧

    目录 一.关于 MongoDB 二.Spring-Data-Mongo 三.整合 MongoDB CRUD A. 引入框架 B. 数据库配置 C. 数据模型 D. 数据操作 E. 自定义操作 四.高级 ...

  8. 补习系列(17)-springboot mongodb 内嵌数据库

    目录 简介 一.使用 flapdoodle.embed.mongo A. 引入依赖 B. 准备测试类 C. 完善配置 D. 启动测试 细节 二.使用Fongo A. 引入框架 B. 准备测试类 C.业 ...

  9. 补习系列(15)-springboot 分布式会话原理

    目录 一.背景 二.SpringBoot 分布式会话 三.样例程序 四.原理进阶 A. 序列化 B. 会话代理 C. 数据老化 小结 一.背景 在 补习系列(3)-springboot 几种scope ...

随机推荐

  1. nginx.conf 中php-ftp配置

    location ~ .php$ { root /home/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_par ...

  2. C#语言struct结构体适用场景和注意事项

    在C#语言中struct结构体和class之间的区别主要是值类型和引用类型的区别,但实际上如果使用不当是非常要命的.从Win32时代过来的人对于struct一点不感觉陌生,但是却反而忽略了一些基本问题 ...

  3. android studio gradle 打jar 包 (混淆+第三方库包)

    将依赖的第三方库打包进自己的jar包 1.先将第三方的库包拿到,然后添加jar包到项目的libs. 2.项目的build.gradle脚本添加下面的task: task buildJar(depend ...

  4. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习8

    #include <iostream> #include <fstream> #include <cstdlib> const int SIZE=20; using ...

  5. 10-HTTPServletReauest和HTTPServletResponse

    Servlet配置方式 1. 全路径匹配 以 / 开始 /a /aa/bb localhost:8080/项目名称/aa/bb 2. 路径匹配 , 前半段匹配 以 / 开始 , 但是以 * 结束 /a ...

  6. pywin32模块安装

    安装流程: 1.查看python版本和位数: 2.下载对应的的pywin32,下载目录任意 https://sourceforge.net/projects/pywin32/files%2Fpywin ...

  7. 关于vue的数据增删的一些细节

    第一种情况:在vue中使用的数据必须先在data中定义数据,不然报错: 第二种情况:访问对象中不存在的值,是可以得到undefined,但是不会报错 第三种:vue只会监听data已经定义的值,后续添 ...

  8. postgrel执行VACUUM报VACUUM cannot run inside a transaction block

    在python脚本里执行: sql_gp1 = "VACUUM dwd_access_record_inout_temp" sql_gp2 = "delete from ...

  9. webapi 知识点

    在web api 中后台的方法必须 加入 [HttpGet] ,[HttpPost],[HttpPut],[HttpDelete] 来区分,这是一种习惯. ps: get 方式参数都存在http协议头 ...

  10. [译]async/await中阻塞死锁

    这篇博文主要是讲解在async/await中使用阻塞式代码导致死锁的问题,以及如何避免出现这种死锁.内容主要是从作者Stephen Cleary的两篇博文中翻译过来. 原文1:Don'tBlock o ...