javaspring-bootgradlejarexecutable-jar

Jarlauncher was not found when using spring boot layertools mode


I extracted my app build file using layertools jar mode. (ref. https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#container-images.dockerfiles)

As a result, four files were extracted as follows.

application
dependencies
snapshot-dependencies
spring-boot-loader

Then, in the same directory, I tried to run the application by executing the following command:

$java org.springframework.boot.loader.JarLauncher

However, an error occurred.

java.lang.ClassNotFoundException: org.springframework.boot.loader.JarLauncher

MANIFEST.MF is as follows.

Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.henry.myproject.HelloApplicationKt
Spring-Boot-Version: 2.6.4
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx

Why does this error occur?


Solution

  • Each of the four directories is intended to be used as a separate layer in a Docker image. They need to be copied into a single directory. In a Dockerfile, that would look like this:

    COPY --from=builder application/dependencies/ ./
    COPY --from=builder application/spring-boot-loader/ ./
    COPY --from=builder application/snapshot-dependencies/ ./
    COPY --from=builder application/application/ ./
    

    The application can then be launched from the directory into which the layers have been copied.