Packaging the App as a Jar
A jar is one file that holds the whole app and everything it needs to run. The mvn package command builds that file from the project.
The plugin block
This block tells Maven to pack the app. It sits inside the plugins list in pom.xml.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>Build the jar
Run this command in the project folder. Maven builds the jar and puts it in target.
mvn packageExample
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
mvn packageKey points
- A jar is one file that holds the whole app.
- Maven is the build tool that makes the jar.
- The spring-boot-maven-plugin packs the app for running.
- The plugin block goes in the build part of pom.xml.
- Pom.xml is the file that lists the project build and its parts.
- The built jar lands in the target folder.
In this example, the build block holds the plugins for the project. The spring-boot-maven-plugin packs the app into one runnable jar. The mvn package command runs the build. Maven writes the finished jar into the target folder. The jar path is target/demo-0.0.1-SNAPSHOT.jar.
Note
The jar name carries the version from pom.xml.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command builds the jar?