In this article, we are going to present how to create a runnable JAR file out of a Spring Boot application. One of the best features of Spring Boot is embedded web containers which allow us to pack the whole application with dependencies into a single jar file ready to deploy and run.
2. Maven configuration
To create a fat jar with Spring Boot we need an additional spring-boot-maven-plugin in our pom.xml file:
With that Maven configuration, we can build our Spring Boot project using mvn clean install. To run our application we simply executing generated jar file in the target directory.
we should see Spring Boot starting output logs on the console:
To stop the application we need to find that process and terminates it:
3. Additional Maven configuration
If we are not inheriting spring-boot-starter-parent in the pom.xml file we could still create executable Spring Boot jar bu adding a main class in the Maven plugin:
We could also point that class in properties section:
Note that if we are using correct annotations and in the pom.xml file we inherited from spring-boot-starter-parent we don't need to add main-class related values.
In this article, we presented a simple way to build Spring Boot in a runnable JAR file.