Spring
SpringBoot
Spring Boot With Executable Jar
Build Spring Boot Executable Jar By Maven
During developing spring boot application, we usually use IDE to run our Spring Boot application. However, when we need to release or deploy on servers we need to build and wrap it into executable jar file or war file.
So to build a Spring Boot application into an executable jar, we need to add the plugin below into the pom.xml
file.
pom.xml 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <build>
<plugins>
<plugin>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-maven-plugin</artifactId>
<version> 2.6.3</version>
<executions>
<execution>
<id> build-info</id>
<goals>
<goal> build-info</goal>
</goals>
</execution>
<execution>
<id> repackage</id>
<goals>
<goal> repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The spring-boot-maven-plugin
dependency is a Maven plugin that can be used to build, package, and run Spring Boot applications.
spring-boot-maven-plugin
contains 3 goals which are:
build-info
: This goal generates build information, such as the version number and the build timestamp.
repackage
: This goal repackages the application into a single executable JAR file.
run
: This goal runs the application in an embedded Jetty container.
After adding the plugin above, then you can use the maven command below to build your Spring Boot project.
After building your project, you can see a jar file generated in the target
folder as below.
Then you can test by using command below to run this jar file.
java -jar json-schema-validator-0.0.1-SNAPSHOT.jar
See Also
References