Search code examples
spring-bootmanifestspring-boot-maven-plugin

Does jar manifest support `Class-Path`? Why use spring-boot-loader instead?


I know that spring boot packages an executable jar with spring-boot-loader and loads other jars from BOOT-INF/lib as described in this post, using a class named JarLauncher.

After reading this post, I was thinking that Class-Path in manifest can do this, too.

So why does spring boot do so many works to load jars from a customed BOOT-INF/lib, rather than just write simply in META-INF/MANIFEST.MF:

Class-Path: BOOT-INF/lib

Solution

  • The Class-Path manifest approach does not support loading classes from jar files nested within a jar. From the Oracle documentation that you've linked to in your question:

    The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

    Spring Boot's JarLauncher and the other classes in spring-boot-loader are the custom code that allow classes to be loaded from jars nested within a jar.