补习系列-springboot-使用assembly进行项目打包
2019-08-13 17:46
1416 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/devcloud/article/details/99414240
目录
springboot-maven插件
repackage目标声明
[code] 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
[code]<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插件完成重复打包
构建结构
[code]base - bin - start.sh - stop.sh - application.properties - log4j.properties - app-0.0.1-SNAPSHOT.jar
pom定义
[code]<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定义
[code]<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>/</ 3ff7 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依赖
[code]<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范围的依赖
[code]<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内置变量
作者:zale
相关文章推荐
- Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip
- 使用gradle的application插件进行Spring-boot项目打包
- SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)
- Windows下使用Jenkins进行Spring Boot项目自动打包运行
- Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip
- SpringBoot项目使用maven-assembly-plugin根据不同环境打包成tar.gz
- maven-如何使用maven对springboot项目进行打包
- 使用Eclipse对SpringBoot项目如何进行打包部署
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- springboot项目中使用MockMvc进行单元测试
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- spring boot项目中使用spring-boot-devtools模块进行代码热部署,避免重新启动web项目
- Springboot或Java web项目使用maven打包时引入外部源
- SpringBoot系列三、使用工具自动创建Web项目
- springboot项目中使用redis对数据进行解析报Invalid numeric value: Leading zeroes not allowed错误
- Spring boot项目 使用ip+port+contextPath进行访问的时候会直接显示出项目中的一些接口信息和相关数据