11.5 creating an executable jar
spring-boot-maven-plugin
Executable jars (sometimes called “fat jars”) are archives containing your compiled classes along with all of the jar dependencies that your code needs to run.
To create an executable jar we need to add the spring-boot-maven-plugin
to our pom.xml
.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
這里使用spring-boot提供的maven插件spring-boot-maven-plugin
對編譯后的class文件與依賴進行打包纫事,打包成可執(zhí)行jar
maven打包命令:mvn package
查看jar包內容:jar tvf xx.jar
執(zhí)行jar:java -jar xx.jar
maven-assembly-plugin
13.1 Dependency management - Maven
每個版本的springboot都會對應的包含常用的依賴谎亩,我們使用的時候不需要指定版本,可以通過pom繼承spring-boot-starter-parent
來獲得這些默認配置
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
如果想要自己指定版本,可以通過<properties>
標簽來指定覆蓋
<properties>
<spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
</properties>
13.2.2 Using Spring Boot without the parent POM
很多情況我們需要繼承自定義的parent pom奕巍,但仍可使用springboot幫我們定義好的dependency management
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type> <!--相應的依賴產品包形式-->
<scope>import</scope> <!--它只使用在<dependencyManagement>中摧找,表示從其它的pom中導入dependency的配置-->
</dependency>
</dependencies>
</dependencyManagement>
如果需要覆蓋dependency management中的某個依賴养交,已經不能通過<properties>
來實現(xiàn)了抓狭,需要在spring-boot-dependencies
前進行依賴定義
<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<!-- this is a BOM(bill of materials) -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
13.5 Starters
springboot集成了spring提供的絕大部分服務,依賴描述符以spring-boot-starter-*開頭线欲,可以直接拿來使用
starter poms也可以進行自定義明场,命名開頭acme-spring-boot-starter,看完后再更新如何自定義
更多springboot的maven配置李丰,之后詳細學習文檔后更新...