In this maven tutorial, we will learn to create fat jar or uber jar for spring boot applications using maven plugin. Its very easy and require very few config changes in pom.xml
file.
Step 1 – Add Spring boot maven plugin in pom.xml
First step and probably only step required is to have spring-boot-maven-plugin
plugin entry in your pom.xml
file.
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
Read More: Create fat jar using maven shade plugin
Step 2 – Run the maven build
Now when you run the maven build using simple command mvn clean install
, it will generate the fat jar for your project consisting all compiled application code as well as all its dependencies – packaged inside one big jar file.
mvn clean install
Demo
You can download the sourcecode of Spring Boot REST API Example into your machine to run the demo. You can optionally import this project as maven project into eclipse, if you wish to look inside the project code.
Imported project structure

Generated fat jar file

Complete pom.xml file used in demo
<?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.howtodoinjava.demo</groupId> <artifactId>springbootdemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>SpringBootDemo</name> <description>Spring Boot Demo for https://howtodoinjava.com</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-hateoas</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
That’s all for this quick tip. Drop me your questions in comments section.
Happy Learning !!
Sumit Tyagi
I added one local maven dependency with spring boot maven build (same as above). In maven-dependencies it is showing that jar file. But while building (maven clean install) only that jar file’s content is not reflecting and build fails.
also shows that the file is in classpath. Does spring boot maven build excludes local repositories? (which are not pulled from some maven repository and are only in local .m2 repository)
ben
how to make jar , which able to take server class paths, for the excluded dependencies
Hidayathulla Khan
How to generate jar file for gradle build with version 2.14