Maven settings

Apache Maven is probably the most common build management system: we can consider it the de facto build and package operation for Java applications. In this section, we will use it to build and package our application.

Spring Boot is compatible with Apache Maven 3.2 or higher, and, in order to easily manage all of the Spring Boot dependencies (in particular, the right versions), you can set your Maven POM file to inherit from the spring-boot-starter-parent project.

The following is an example of a pom.xml file that you can use in your Spring Boot application:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

As usual, you will be able to build and package your application with the following command:

$ mvn clean package
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset