spring-boot-maven-plugin doesn't create fat jar

11,169

it seems you are using a wrong command. mvn clean package is maven command, you should use command 'repackage', it used for

Repackages existing JAR and WAR archives so that they can be executed from the command line using java -jar

as it mentioned here https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html

Or probably it's plugin configuration issue. Just checked: it works with spring-boot-maven-plugin-2.0.0.RELEASE

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                 <classifier>exec</classifier>
            </configuration>
         </execution>
    </executions>
</plugin>
Share:
11,169
Pankaj
Author by

Pankaj

Updated on June 17, 2022

Comments

  • Pankaj
    Pankaj almost 2 years

    I'm using spring-boot-maven-plugin to package my REST service. I'm building the jar using mvn clean install or mvn clean package. After I decompile the jar, I don't find any of the dependencies added (I was expecting it to be a fat jar with all dependencies)

    enter image description here

     <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.9.RELEASE</version>
        <executions>
            <execution>
               <phase>install</phase>
               <goals>
                  <goal>repackage</goal>
                  <goal>build-info</goal>
               </goals>
            </execution>
        </executions>
        <configuration>
            <executable>true</executable>
            <finalName>myapp</finalName>
            <includeSystemScope>true</includeSystemScope>
        </configuration>
    </plugin>
    

    When I run the spring boot using java -jar myapp.jar -Drun.jvmArguments="-Dspring.profiles.active=qal" I'm getting ClassNotFoundException for many of the classes. It's clear that artifact didn't build as expected. However, if I start spring boot application using maven ./mvnw spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=qal" I guess, it finds all the dependencies in target folder hence works fine. How can I fix the build issue so that I can start app using java -jar command.

    EDIT: It's multi-module maven project

  • Pankaj
    Pankaj about 6 years
    I used "mvn clean package spring-boot:repackage". I see all project classes are compiled and added to the jar but dependencies are still missing and I continue to get the ClassNotFound error for dependencies
  • Pankaj
    Pankaj about 6 years
    Found the reason why it wasn't working. My project is multi module maven project. Need to use classifier as per this documentation. It works with 1.5.9.RELEASE version as well. docs.spring.io/spring-boot/docs/current/maven-plugin/example‌​s/…
  • frido
    frido about 5 years
    Hi, please give a short description on why or how this code will solve the OPs question.
  • Shantanoo K
    Shantanoo K almost 5 years
    The answer does not explain what and how the original issue will get solved.
  • carlos palma
    carlos palma over 2 years
    The link posted in the answer is broken