springboot-maven配置

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文件与依赖进行打包,打包成可执行jar
maven打包命令:mvn package
查看jar包内容:jar tvf xx.jar
执行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>来实现了,需要在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配置,之后详细学习文档后更新...

posted on 2018-01-02 13:58  simple_huang  阅读(6429)  评论(0编辑  收藏  举报