案例代碼:https://gitee.com/flymini/codes02/tree/master/maven_plugins_/com-learn-plugin02
****
appassembler-maven-plugin 可以為 Java 項目自動生成啟動腳本,但是做不到將生成的資源打包成壓縮包,需要配合插件 maven-assembly-plugin 才能做到。
<br/>
步驟如下:
**1. pom 中引入兩個插件**
```xml
<build>
<plugins>
<!-- spring-boot-maven-plugin插件與appassembler-maven-plugin插件不兼容,不要將spring-boot-maven-plugin插件引進來 -->
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<platforms>
<platform>unix</platform>
<platform>windows</platform>
</platforms>
<!--打包后生成的target目錄路徑,如D:/workspace/com-learn-plugin02/target-->
<assembleDirectory>${project.build.directory}/${project.name}</assembleDirectory>
<!-- flat與lib共同決定將項目用的的所有jar包復制到lib目錄下 -->
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
<!--啟動腳本存放在bin目錄-->
<binFolder>bin</binFolder>
<!--配置文件存放在conf目錄路徑-->
<configurationDirectory>conf</configurationDirectory>
<!--是否copy配置文件-->
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<!--從哪里copy配置文件-->
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<binFileExtensions>
<!-- 針對不同平臺生成不同類型的啟動腳本 -->
<unix>.sh</unix>
<windows>.bat</windows>
</binFileExtensions>
<encoding>UTF-8</encoding>
<logsDirectory>logs</logsDirectory>
<tempDirectory>tmp</tempDirectory>
<daemons>
<daemon>
<!-- 啟動腳本的名稱,Linux平臺上就是:app,windows平臺上就是app.bat -->
<id>app</id>
<!-- 啟動類 -->
<mainClass>com.learn.plugin02.Plugin02Application</mainClass>
<platforms>
<platform>jsw</platform>
</platforms>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<include>linux-x86-32</include>
<include>linux-x86-64</include>
<include>windows-x86-32</include>
<include>windows-x86-64</include>
</includes>
</generatorConfiguration>
</generatorConfigurations>
<jvmSettings>
<!-- 啟動時的一下jvm參數配置 -->
<extraArguments>
<extraArgument>-server</extraArgument>
<extraArgument>-Xms256M</extraArgument>
<extraArgument>-Xmx256M</extraArgument>
<extraArgument>-Xss512k</extraArgument>
<extraArgument>-Xloggc:logs/demo_gc.log</extraArgument>
<extraArgument>-verbose:gc</extraArgument>
<extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument>
<extraArgument>-XX:HeapDumpPath=logs/java_heapdump.hprof</extraArgument>
</extraArguments>
</jvmSettings>
</daemon>
</daemons>
<programs>
<program>
<mainClass>com.learn.plugin02.Plugin02Application</mainClass>
<id>demoApp</id>
</program>
</programs>
</configuration>
<!-- 如果不配置 generate-daemons,則打包命令為 mvn clean package appassembler:generate-daemons -->
<!-- 如果配置了 generate-daemons,打包命令可以是 mvn clean package 也可以是 mvn clean package appassembler:generate-daemons -->
<executions>
<execution>
<inherited>true</inherited>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- 壓縮包名稱 -->
<finalName>${project.artifactId}</finalName>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
**2. `src/main/assembly/assembly.xml`**
```xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>${project.version}</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<!-- 將appassembler插件生成的資源輸出到壓縮包的根目錄下 -->
<fileSet>
<directory>${basedir}/target/generated-resources/appassembler/jsw/app/</directory>
<outputDirectory>/</outputDirectory>
<fileMode>0777</fileMode>
</fileSet>
</fileSets>
</assembly>
```
**3. 執行`mvn clean package`打包**
**4. 生成的壓縮包及其目錄結構**
```
壓縮包:target/com-learn-plugin02-1.0-SNAPSHOT.tar.gz
壓縮包目錄結構如下:
|—— com-learn-boot14
| |—— bin
| | |—— app
| | |—— app.bat
| | |—— wrapper-linux-x86-32
| | |—— wrapper-linux-x86-64
| | |—— wrapper-linux-x86-32.exe
| | |—— wrapper-linux-x86-64.exe
| |—— conf
| | |—— application.yml
| | |—— wrapper.conf
| |—— lib
| | |—— ..jar
| |—— logs
| |—— tmp
```
- Mybatis
- mybatis是什么
- mybatis優缺點
- 環境搭建
- 使用步驟
- 傳參方式
- 無需傳參
- 一個參數
- 多個參數
- 增/刪/改
- 查詢
- 單表查詢
- 一對一查詢
- 一對多查詢
- 動態SQL
- 注解操作
- Spring
- Spring什么
- Spring優點
- Spring組成
- 第一個Spring程序
- 兩大核心技術
- IoC控制反轉
- IoC思想
- IoC容器使用步驟
- 屬性注入
- IoC注入方式
- 模擬IoC實現
- AOP
- AOP概念
- AOP原理
- AOP關鍵術語
- AOP編程過程
- 切入點規則
- 5種增強方式
- Spring注解開發
- 注解開發的優勢
- Bean注解開發
- AOP注解開發
- 完全注解開發
- 模擬Spring注解開發
- 自動裝配
- 配置文件拆分
- SpringBean
- Bean常用屬性
- Bean的作用域
- Bean的生命周期
- Spring整合MyBatis
- 整合步驟
- SqlSessionTemplate
- 業務層添加事務
- 事務的作用
- 配置文件事務
- 注解事務
- 事務參數
- SpringMVC
- SpringMVC是什么
- 環境搭建
- 請求流程
- 核心組件
- 前后端交互
- 簡單交互演示
- 常用注解
- 后端數據傳遞至前端
- ServletAPI
- 訪問靜態資源
- 異常處理
- HandlerExceptionResolver
- 局部異常
- 全局異常
- 轉發與重定向
- 轉發演示
- 重定向演示
- 轉發與重定向的區別
- 獲取表單數據
- 表單標簽
- REST風格的URL
- 異步處理
- 異步請求
- JSON數據處理
- 中文亂碼處理
- 日期處理
- 上傳文件
- 攔截器
- 視圖解析器
- 視圖類型
- 多視圖解析器
- 自定義pdf視圖
- JSR303數據驗證
- JSR303是什么
- 常用約束
- 使用步驟
- SpringMVC整合Mybatis
- 整合步驟
- Mybatis分頁插件
- SpringBoot
- SpringBoot是什么
- 環境搭建
- SpringBoot啟動分析
- SpringBoot啟動類
- 啟動過程
- SpringBoot配置文件
- 配置文件類型
- 更改配置文件
- 讀取配置文件
- 占位符
- 配置優先級
- 自定義IoC容器
- 定義方式
- 引入Spring配置文件
- @Configuration
- SpringBoot自動配置
- 自動配置原理
- 條件注解
- 自動配置報告
- 自定義自動配置
- 關閉自動配置
- 接管自動配置
- 多環境配置
- CommandLineRunner
- SpringBoot與Web開發
- 引入模板引擎
- Thymeleaf模板
- Freemarker模板
- 靜態資源訪問
- webjars
- 靜態資源位置
- ico圖標
- 指定首頁
- 更換Web服務器
- 國際化
- 攔截器
- 錯誤處理機制
- 錯誤處理機制原理
- 定制錯誤頁面
- 定制錯誤數據
- 上傳文件
- 注冊servlet三大組件
- 注冊Servlet
- 注冊過濾器
- 注冊監聽器
- 外部Tomcat與jsp模板
- 前后端交互
- 傳遞json字符串
- 傳遞js對象
- 傳遞表單
- 下載功能
- Swagger2文檔
- SpringBoot整合JDBC
- 整合步驟
- 核心API
- JdbcTemplate
- 增刪改
- 查詢
- NamedParameterJdbcTemplate
- 增刪改
- 查詢
- SpringBoot整合Mybatis
- 整合步驟
- 切換為Druid數據源
- 添加事務
- Mybatis分頁插件
- 場景啟動器
- 場景啟動器是什么
- 自定義場景啟動器
- SpringBoot與日志
- 日志框架
- slf4j日志
- slf4j日志實現
- 統一切換為slf4j
- 日志配置
- 日志文件
- 切換日志框架
- 切換日志場景啟動器
- SpringBoot與緩存
- JSR107緩存技術
- Spring緩存抽象
- 緩存注解
- SpEL表達式
- 使用緩存
- 自定義key生成器
- 緩存工作原理與流程
- SpringBoot整合Redis
- 整合步驟
- 初步使用
- 序列化機制
- 緩存管理器
- SpringBoot與任務
- 異步任務
- 實現異步任務
- 注意事項與原理
- 自定義線程池
- 定時任務
- cron表達式
- 創建定時任務
- @Scheduled參數
- 動態時間
- 郵件任務
- Quartz定時任務
- Quartz是什么
- 創建定時任務
- 觸發器與任務
- 任務的CURD
- 兩種觸發器
- 并發問題
- 持久化
- 任務持久化
- Quartz集群
- misfire策略
- 打包插件
- appassembler-maven-plugin
- appassembler與assembly配合