Chinaxiang / spring-boot-assembly

spring boot assembly base project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-boot-assembly

spring-boot项目模板

  1. 在spring boot项目中使用maven profilesmaven assembly插件根据不同环境打包成tar.gz或者zip或者dir
  2. 将spring boot项目中的配置文件提取到外部config目录中
  3. 将spring boot项目中的启动jar包移动到boot目录中
  4. 将spring boot项目中的第三方依赖jar包移动到外部lib目录中
  5. bin目录中是启动,停止,重启服务命令

主要插件

  1. maven-assembly-plugin
  2. maven-jar-plugin
  3. spring-boot-maven-plugin
  4. maven-dependency-plugin
  5. 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

参考

About

spring boot assembly base project

License:Apache License 2.0


Languages

Language:Shell 51.3%Language:Java 39.6%Language:Batchfile 7.3%Language:HTML 1.5%Language:JavaScript 0.3%