spring-boot-assembly
spring-boot项目模板
- 在spring boot项目中使用
maven profiles
和maven assembly
插件根据不同环境打包成tar.gz或者zip或者dir - 将spring boot项目中的配置文件提取到外部config目录中
- 将spring boot项目中的启动jar包移动到boot目录中
- 将spring boot项目中的第三方依赖jar包移动到外部lib目录中
- bin目录中是启动,停止,重启服务命令
主要插件
- maven-assembly-plugin
- maven-jar-plugin
- spring-boot-maven-plugin
- maven-dependency-plugin
- maven-resources-plugin
涉及到的变量解释:
@profileActive@
=dev
@build.directory@
=target
@build.outputDirectory@
=target/classes
@build.finalName@
=spring-boot-assembly
@build.sourceDirectory@
=src/main/java
@basedir@
=.
@project.name@
=spring-boot-assembly
项目源码结构
├─bin
│ restart.sh
│ shutdown.sh
│ startup.bat
│ startup.sh
├─logs
│ startup.log
├─main
│ ├─assembly
│ │ assembly.xml
│ ├─java
│ │ └─com
│ │ └─quanshi
│ │ └─springbootassembly
│ │ ├─controller
│ │ │ HelloController.java
│ │ ├─orm
│ │ └─Application.java
│ └─resources
│ │ application.yml
│ │ application-dev.yml
│ │ application-prod.yml
│ │ application-test.yml
│ │ logback-spring.xml
│ ├─db
│ │ schema.sql
│ │ data.sql
│ ├─static
│ │ index.js
│ └─templates
│ index.html
└─test
项目打包
mvn clean package -Pdev
使用package脚本打包
window
package.bat dev
linux/mac
bash package.sh dev
打包的压缩包,target目录下
spring-boot-assembly-${profile}-${version}.tar.gz
linux解压tar.gz
tar -zxvf spring-boot-assembly-${profile}-${version}.tar.gz
解压后的目录结构
└─spring-boot-assembly
│ LICENSE
│ README.md
├─bin
│ restart.sh
│ shutdown.sh
│ startup.bat
│ startup.sh
├─boot
│ spring-boot-assembly.jar
├─config
│ application-*.yml
│ application.yml
│ logback-spring.xml
└─lib
**.jar
window启动
bin/startup.bat
linux启动,停止,重启
bash bin/startup.sh [dev|prod|test] 启动项目
bash bin/shutdown.sh 停止服务
bash bin/restart.sh 重启服务
项目访问
http://localhost:8080/example/hello?name=tom
构建脚手架
基于本项目构建脚手架命令
mvn archetype:create-from-project
经过优化调整得到项目:sba-archetype
参考
- https://docs.spring.io/spring-boot/docs/current/maven-plugin/
- https://maven.apache.org/components/plugins/maven-assembly-plugin/usage.html
- https://maven.apache.org/plugins/maven-jar-plugin/
- https://maven.apache.org/components/plugins/maven-dependency-plugin/
- https://maven.apache.org/plugins/maven-resources-plugin/
- https://maven.apache.org/guides/introduction/introduction-to-profiles.html