Skip to content
Advertisement

Spring boot maven plugin: mvn clean package does not layered jar file automatically

I got trouble with spring-boot-maven-plugin build process. I just want to build

excutable “layered” jar file for optimizing docker image. As document said this build process will produce layered jar by default https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/. Here is apart of my pom.xml file

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <layers>
                    <enabled>true</enabled>
                </layers>
            </configuration>
        </plugin>
    </plugins>
</build>

I used spring boot 2.5.5, maven 3.6.3
Some steps produce:

mvn clean package
jar -tf target/[excutableJarFile].jar

This filesystem of excutableJarFile is just BOOT-INF, META-INF and org although it should be

  1. dependencies
  2. spring-boot-loader
  3. snapshot-dependencies
  4. application

Advertisement

Answer

Enabling the layering feature of the Spring Boot Maven plugin does not change the layout of the generated jar file. It does enable the generation of a layers.idx file that describes how the application is layered, as described in the Spring Boot documentation.

You can use the layertools mode of the generated jar to extract the contents of the jar into a layered structure. See the Dockerfile example in the documentation for more information on how this works.

5 People found this is helpful
Advertisement