Spring Boot maven Plugin

Source: Internet
Author: User

The Spring boot Maven plugin provides the following steps for using the Spring boot application:

RePack: creates a jar or war file that can be executed automatically. It can replace a regular artifact, or it can be attached to the build life cycle using a separate classifier.

run: Run your spring-guided application with several options to pass parameters.

start and stop: integrate the Spring boot application into the integration testing phase so that the application starts before it.

build Information: generates build information that can be used by the actuator.

Repackage an application

In order to repackage the application, you only need to add a reference to the plug-in in Pom.xml, configured as follows:

<Build>
...
<Plugins>
...
<Plugin>
<Groupid>org.springframework.boot</Groupid>
< artifactid>spring-boot-maven-plugin </ artifactid>
      < version>1.5.6.release </ version>
      < executions>
        < execution>
          < Goals>
            < goal>repackage </ goal>
          </ goals>
        </ Execution>
      </ executions>
    </ plugin>
   , .....
  </ plugins>
 ..
</ build>

Repackage the jar or war that was built in the package phase of the Maven life cycle, including any provided dependencies defined in the project.

By default, Devtools is automatically excluded (you can use the Excludedevtools property to control). In order for these jobs to match the war wrapper, the "Spring-boot-devtools" dependency must be set to an optional or provided range. The original (or non-executable) file is renamed to. Original by default, but you can also use a custom classifier to preserve the original artifacts.

The Spring Boot maven plugin overrides the configuration, especially it manages Main-class and Start-class entries, so if the default values do not work, you must configure them (not in the jar plug-in). The main class is actually controlled by the layout properties of the bootstrap plug-in, as an example:

<Build>
...
<Plugins>
...
<Plugin>
<Groupid>org.springframework.boot</Groupid>
<Artifactid>spring-boot-maven-plugin</Artifactid>
<Version>1.5.6.release</Version>
<Configuration>
<Mainclass>${start-class}</ Mainclass>
        < layout>zip </ layout>
      </ configuration>
      < executions>
        < execution>
          < goals
            < goal>repackage </ goal>
          </ goals>
        </ execution
      </ executions>
    </ plugin>
  &NBSP, .....
  </ plugins>
 ..
</ build>

The Layout Property base archive type (jar or war). Can be used in the following layouts:

jar: General executable jar layout.

War: executes the war layout. The provided dependencies are placed in web-inf/lib to avoid conflicts when the war is deployed in the servlet container.

ZIP (dir alias): similar to the jar layout using Propertieslauncher.

MODULE: bundle dependencies (excluding provided scopes) and project resources, do not bundle the bootloader.

NONE: Bundle all dependencies and resources and do not bundle the boot loader.

Running the application

The Spring boot Maven plugin can be used to launch applications from the command line, with the following commands:

mvn spring-boot:run

By default, the application executes directly from the Maven JVM. If you need to run in a forked process, you can use the ' fork ' option. If the ' jvmarguments ' or ' agent ' option is specified, or if there is devtools, a fork will also occur.

If you need to specify some JVM parameters (that is, for debugging purposes), you can use the jvmarguments parameter. For convenience, the configuration file to be enabled is handled by a specific property (profile).

Using integration Testing

To ensure that the life cycle of the spring boot application is properly managed in the integration test, you can use the startup and termination described below:

<Build>
...
<Plugins>
...
<Plugin>
<Groupid>org.springframework.boot</Groupid>
<Artifactid>spring-boot-maven-plugin</Artifactid>
<Version>1.5.6.release</Version>
<Executions>
<Execution>
<Id>pre-integration-test</Id>
<Goals>
<Goal>start</Goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>

You can also configure more advanced settings to skip integration tests when setting specific properties:

<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.6.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: If you run MVN verify-dit.skip=true, the integration test will be skipped completely.

Spring Boot maven Plugin

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.