刘洪青 | a657c13 | 2018-08-21 16:42:54 +0800 | [diff] [blame] | 1 | |
| 2 | ## Maven 构建 spring boot 可执行jar 相关配置 |
| 3 | |
| 4 | (pluginManagement 模式) |
| 5 | |
| 6 | |
| 7 | ### 配置 |
| 8 | |
| 9 | #### 主 pom,设置可用插件(如:samples/pom.xml) |
| 10 | |
| 11 | ``` |
| 12 | <build> |
| 13 | <pluginManagement> |
| 14 | <plugins> |
| 15 | <plugin> |
| 16 | <groupId>org.springframework.boot</groupId> |
| 17 | <artifactId>spring-boot-maven-plugin</artifactId> |
| 18 | <executions> |
| 19 | <execution> |
| 20 | <id>boot-repackage</id> |
| 21 | <phase>package</phase> |
| 22 | <goals> |
| 23 | <goal>repackage</goal> |
| 24 | </goals> |
| 25 | </execution> |
| 26 | </executions> |
| 27 | </plugin> |
| 28 | </plugins> |
| 29 | </pluginManagement> |
| 30 | </build> |
| 31 | ``` |
| 32 | |
| 33 | #### 项目 pom,配置(如:samples/user/pom.xml) |
| 34 | |
| 35 | 增加可执行jar 的启动类 |
| 36 | ``` |
| 37 | <properties> |
| 38 | <start-class>com.supwisdom.leaveschool.user.UserApplication</start-class> |
| 39 | </properties> |
| 40 | ``` |
| 41 | |
| 42 | 设置打包文件名 |
| 43 | ``` |
| 44 | <build> |
| 45 | <finalName>${project.artifactId}</finalName> |
| 46 | </build> |
| 47 | ``` |
| 48 | |
| 49 | 增加打包profile,用于打包时,须指定 -Pboot |
| 50 | ``` |
| 51 | <profiles> |
| 52 | <profile> |
| 53 | <id>boot</id> |
| 54 | <build> |
| 55 | <plugins> |
| 56 | <plugin> |
| 57 | <groupId>org.springframework.boot</groupId> |
| 58 | <artifactId>spring-boot-maven-plugin</artifactId> |
| 59 | </plugin> |
| 60 | </plugins> |
| 61 | </build> |
| 62 | </profile> |
| 63 | </profiles> |
| 64 | ``` |
| 65 | |
| 66 | |
| 67 | ### 构建脚本 |
| 68 | |
| 69 | ``` |
| 70 | mvn clean package -Pboot |
| 71 | ``` |