The spring-boot-maven-plugin of the MAVEN plugin series

Source: Internet
Author: User

The Spring boot maven plugin (Spring boot maven plugin) provides spring boot support for applications in Maven, which provides the possibility for the spring boot application to perform MAVEN operations.
Spring Boot Maven plugin can package the spring boot app as an executable jar or war file, and then run the Spring boot app in the usual way.
The latest version of Spring Boot Maven plugin is 1.5.4.RELEASE released in 2017.6.8, requiring Java 8, MAVEN 3.2, and beyond.

Spring Boot Maven plugin 5 x goals

    • Spring-boot:repackage, default goal. After the MVN package, the executable Jar/war is packaged again, preserving the jar/war generated by the MVN. Origin
    • Spring-boot:run, run the spring boot app
    • Spring-boot:start, in the MVN integration-test phase, manages the spring boot application life cycle
    • Spring-boot:stop, in the MVN integration-test phase, manages the spring boot application life cycle
    • Spring-boot:build-info, generate the build information file used by actuator Build-info.properties

2. Configuring the Pom.xml File

<Build>        <Plugins>            <plugin>                <groupId>Org.springframework.boot</groupId>                <Artifactid>Spring-boot-maven-plugin</Artifactid>                <version>2.0.1.RELEASE</version>                <executions>                    <Execution>                        <Goals>                            <goal>Repackage</goal>                        </Goals>                    </Execution>                </executions>            </plugin>        </Plugins>    </Build>

3.MVN Package Spring-boot:repackage Description

The main goal of Spring Boot Maven plugin is repackage, which, in the Maven package lifecycle phase, is able to package the packages generated by the MVN bundle again as an executable package and MVN Package-generated packages are renamed to *.original.

Based on the above configuration, execute the following command for a project that generates a JAR package

MVN Package Spring-boot:repackage  

You can see the generated two jar files, one is *.jar and the other is *.jar.original.

In the process of executing the above command, MAVEN first packages the build *.jar file in the package phase, and then performs spring-boot:repackage repackaging to find the Main-class attribute configured in the manifest file as follows:

manifest-version:1.0  implementation-title:gs-consuming-rest  implementation-version:0.1.0  Archiver-version:plexus archiver  built-by:exihaxi  implementation-vendor-id:org.springframework  Spring-boot-version:1.5.3.release  Implementation-vendor:pivotal Software, Inc.  Main-class:org.springframework.boot.loader.jarlauncher  start-class:com.ericsson.ramltest.myapplication  spring-boot-classes:boot-inf/classes/  spring-boot-lib:boot-inf/lib/  created-by:apache Maven 3.5.0  build-jdk:1.8.0_131  

Note that the value of the Main-class attribute is org.springframework.boot.loader.JarLauncher;

The Start-class property value is com.ericsson.ramltest.MyApplication.

where the main () method is defined in the Com.ericsson.ramltest.MyApplication class, it is the entry of the program.

Typically, spring boot maven plugin automatically sets the Main-class property for the manifest file during the packaging process, in fact the property actually works, and is also subject to spring boot maven The configuration properties of the plugin are controlled by the layout, as shown below

<plugin>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-maven-plugin</Artifactid>    <version>1.5.4.RELEASE</version>    <Configuration>      <MainClass>${start-class}</MainClass>      <Layout>Zip</Layout>    </Configuration>    <executions>      <Execution>        <Goals>          <goal>Repackage</goal>        </Goals>      </Execution>    </executions>  </plugin> 

Note that the Layout property value here is zip.

The value of the layout property can be as follows:

    • Jar, which is the usual executable jar

Main-class:org.springframework.boot.loader.jarlauncher

    • War, the usual executable war, requires the servlet container to be dependent on the web-inf/lib-provided

Main-class:org.springframework.boot.loader.warlauncher

    • ZIP, dir, similar to jar

Main-class:org.springframework.boot.loader.propertieslauncher

    • MODULE, which packages all dependent libraries (except for the scope of provided), but does not package any launcher of spring boot
    • NONE, package all dependent libraries, but do not package any of the Spring boot launcher

Start/stop of the spring Boot Maven plugin in the 4.integration-test phase

<Properties>    <It.skip>False</It.skip>  </Properties>  <Build>    <Plugins>      <plugin>        <groupId>Org.apache.maven.plugins</groupId>        <Artifactid>Maven-failsafe-plugin</Artifactid>        <Configuration>          <Skip>${it.skip}</Skip>        </Configuration>      </plugin>      <plugin>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-maven-plugin</Artifactid>        <version>1.5.4.RELEASE</version>        <executions>          <Execution>            <ID>Pre-integration-test</ID>            <Goals>              <goal>Start</goal>            </Goals>            <Configuration>              <Skip>${it.skip}</Skip>            </Configuration>          </Execution>          <Execution>            <ID>Post-integration-test</ID>            <Goals>              <goal>Stop</goal>            </Goals>            <Configuration>              <Skip>${it.skip}</Skip>            </Configuration>          </Execution>        </executions>      </plugin>    </Plugins>  </Build>  

Note that the IT.SKIP variable is used as a flag bit for whether to skip Integration-test.

Maven-failsafe-plugin is used as the main execution target of Integration-test.

Spring-boot-maven-plugin is used to provide support for integration-test.

The MAVEN command to execute Integration-test is as follows:

MVN Verify

Or

MVN Verify-dit.skip=false

Reference Links: 68. Spring Boot Maven Plugin

http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/maven-plugin/
Https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html

The spring-boot-maven-plugin of the MAVEN plugin series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.