Spring Boot Maven plugin

Use maven command to create SpringBoot project, please refer to " Create SpringBoot Project Using Maven Command Line"

The SpringBoot Maven plugin provides support for SpringBoot in Maven, allowing packaging executable jars or wars and running applications directly.

The jar packages provided by spring boot are listed in the ~ / .m2 / repository / org / springframework / boot / spring-boot-dependencies / 2.2.5.RELEASE / spring-boot-dependencies-2.2.5.RELEASE.pom file rely. The configuration of the SpringBoot Maven plugin is also included. If not, add the following configuration to your pom.xml file:

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>2.2.5.RELEASE</version>
        </plugin>
        ...
      </plugins>
    </pluginManagement>
  </build>

Now let's take a look at some useful commands provided by the Springboot maven plugin:

command effect
spring-boot:run Run the Spring Boot application
spring-boot:repackage Repackage the existing jar / war, then you can use java -jar to execute them from the command line
spring-boot:startspring-boot:stop Starting and stopping a Spring Boot application, contrary to the run target, it does not prevent and allow other targets to run on the application. This goal is commonly used in integration test scenarios where the application is started before the test suite and stopped after.
spring-boot:build-info Generate a build-info.properties file based on the content of the current MavenProject, which can be used by the actuator.

1.spring-boot:run

~/Desktop/MyProject/springboot$ mvn spring-boot:run

2.spring-boot:repackage

In spring boot, you can directly package the application into a jar / war, and then run the java -jar <name> .jar command to start the jar / war without the need to configure an additional Web Server.

(1) First, if you want to build a jar package or a war package, you need to specify it in pom.xml first:

<project ...>
...
  <packaging>jar</packaging>
...
</project>  

(2) In order to successfully repackage your application and run it with java -jar, you need to add the following configuration to pom.xml:

<build>
	  <plugins>
	  	<plugin>
		  	<groupId>org.springframework.boot</groupId>
		  	<artifactId>spring-boot-maven-plugin</artifactId>
		  	<version>2.2.5.RELEASE</version>
		  	<executions>
			  	<execution>
				  	<goals>
					  	<goal>repackage</goal>
				  	</goals>
			  	</execution>
		  	</executions>
	  	</plugin>
  	</plugins>
  </build>

(3) Perform repackaging

~/Desktop/MyProject/springboot$ mvn package spring-boot:repackage

If you encounter an exception: repackage failed: Source file must be provided, please refer to "Repackage failed: Source file must be provided exception"

3.spring-boot:build-info

Generate a build-info.properties file based on the contents of the current MavenProject.

~/Desktop/MyProject/springboot$ mvn spring-boot:build-info

The result is META-INF / build-info.properties in the target / classes directory:


~/Desktop/MyProject/springboot$ cd target
~/Desktop/MyProject/springboot/target$ tree
.
├── classes
│   ├── com
│   │   └── wong
│   │       ├── App.class
│   │       └── First.class
│   └── META-INF
│       └── build-info.properties
...
~/Desktop/MyProject/springboot/target$ cat classes/META-INF/build-info.properties
build.artifact=springboot
build.group=com.wong
build.name=springboot
build.time=2020-03-22T03\:35\:24.179Z
build.version=1.0.0

4.spring-boot:start 和 spring-boot:stop

~/Desktop/MyProject/springboot$ mvn package spring-boot:start
Published 381 original articles · praised 85 · 80,000 views +

Guess you like

Origin blog.csdn.net/weixin_40763897/article/details/105024623