把 SpringBoot Maven 项目打包成 jar 文件时,我们通常用到 spring-boot-maven-plugin 插件。
前面也介绍过,在 spring-boot-starter-parent POM 和 spring-boot-starter POM 中都有插件的管理,现在我们就撸一把构建元素中插件的用法。
一、spring-boot-maven-plugin 插件的使用
1、项目中 spring-boot-maven-plugin 插件的使用
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent><!--父项目-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--项目基本信息、父项目信息、依赖、自定义属性等等...-->
<build><!--构建元素-->
<plugins><!--插件引入-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>xxx</finalName> <!--jar的名称-->
</build>
</project>
project 标签指定项目的声明。modelVersion 标签指定 POM 模型的版本。目前使用的是 4.0.0 版本。这是 Maven 项目的根元素,定义了项目模型的版本。
parent 标签指定父项目信息,这里继承了 spring-boot-starter-parent 的 pom。
build 标签指定项目的构建配置。它包含了多个子元素,如 、 和 < finalName > 等等。
spring-boot-maven-plugin 插件用于打包和运行 Spring Boot 应用。
2、spring-boot-starte