SoFunction
Updated on 2025-04-08

Use spring-boot-maven-plugin plugin to package SpringBoot application method

Spring-boot-maven-plugin plugin package SpringBoot application

spring-boot-maven-plugin can make Spring Boot applications into jar packages with dependencies.

That is, the package not only contains the application's own code, but also contains the dependencies configured in it.

Revise

    <build>
       <plugins>
           <plugin>
               <groupId></groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <executions>
                   <execution>
                       <goals>
                           <goal>repackage</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>
       </plugins>
    </build>

Pack

$ mvn compile
$ mvn package spring-boot:repackage

In this way, the generated jar package contains the project dependencies, and the generated jar package is located in the project's target folder.

Compare the similarities and similarities of the two directories

Assume that the project structure is

|-src
  |- main
     |- java
       |- cn
  |- resources
     |- 
|- 
mv package mvn package spring-boot:repackage
jar package size Very small, usually only a few dozen to hundreds of KB It is too large, usually more than ten MB, depending on how much the project depends on
Table of contents -cn folder is the compiled class file
-META-INF folder contains project files
- Project configuration file
-BOOT-INF contains the compiled class file and project configuration file project-related dependencies
-META-INF internally contains file l

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.