Inside Spring Boot’s Executable JAR: How JarLauncher Boots Your Application

This article explains how Spring Boot’s spring-boot-maven-plugin packages an application into an executable JAR, details the internal jar layout, the role of the MANIFEST.MF and JarLauncher, and walks through the custom class‑loading mechanism that launches the Spring application.

Programmer DD
Programmer DD
Programmer DD
Inside Spring Boot’s Executable JAR: How JarLauncher Boots Your Application

SpringBoot provides the spring-boot-maven-plugin to package an application into an executable JAR. Adding the plugin in the pom.xml is sufficient.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The generated executable-jar-1.0-SNAPSHOT.jar has the following internal structure:

├── META-INF
│   ├── MANIFEST.MF
│   └── maven
│       └── spring.study
│           └── executable-jar
│               ├── pom.properties
│               └── pom.xml
├── lib
│   ├── aopalliance-1.0.jar
│   ├── classmate-1.1.0.jar
│   ├── spring-boot-1.3.5.RELEASE.jar
│   ├── spring-boot-autoconfigure-1.3.5.RELEASE.jar
│   ├── ...
├── org
│   └── springframework
│       └── boot
│           └── loader
│               ├── ExecutableArchiveLauncher$1.class
│               ├── ...
└── spring
    └── study
        └── executablejar
            └── ExecutableJarApplication.class

You can start the program directly with: java -jar executable-jar-1.0-SNAPSHOT.jar The fat JAR contains four types of files:

META-INF folder: program entry, with MANIFEST.MF describing the JAR. lib directory: third‑party dependency JARs.

Spring Boot loader related classes.

The module’s own classes.

The MANIFEST.MF includes a Main-Class of org.springframework.boot.loader.JarLauncher, which is invoked when the JAR is executed.

JarLauncher is part of Spring Boot Loader and is responsible for launching the application class defined by the Start-Class attribute.

Spring Boot Loader abstract classes

Launcher – abstract base for various launchers (JarLauncher, WarLauncher, PropertiesLauncher).

Archive – abstraction of an archive file; JarFileArchive represents a JAR file, ExplodedArchive represents an exploded directory.

JarFile – wraps a JAR file and provides access to its entries.

Example URLs used by the custom org.springframework.boot.loader.jar.Handler protocol:

jar:file:/Users/format/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-starter-web-1.3.5.RELEASE.jar!/

jar:file:/Users/format/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-loader-1.3.5.RELEASE.jar!/org/springframework/boot/loader/JarLauncher.class

JarLauncher execution flow

The main method creates a JarLauncher and calls launch(args). The launch method registers the custom URL protocol handler, builds a class loader from the archives in lib, obtains the Start-Class from the manifest, and starts it in a new thread.

public static void main(String[] args) {
    new JarLauncher().launch(args);
}

The launch method creates a ClassLoader, then calls an overloaded launch(args, mainClass, classLoader) which creates a MainMethodRunner that reflects the main method of the start class and invokes it.

Custom class loader LaunchedURLClassLoader

It overrides loadClass to try the root class loader, then locate the class locally using findClass, and finally fall back to the standard parent delegation.

private Class<?> doLoadClass(String name) throws ClassNotFoundException {
    // 1) try the root class loader
    try {
        if (this.rootClassLoader != null) {
            return this.rootClassLoader.loadClass(name);
        }
    } catch (Exception ex) {
        // ignore and continue
    }
    // 2) try to find locally
    try {
        findPackage(name);
        Class<?> cls = findClass(name);
        return cls;
    } catch (Exception ex) {
        // ignore and continue
    }
    // 3) use standard loading
    return super.loadClass(name, false);
}

The findClass implementation searches the URLs of the nested JARs, obtains the resource, and defines the class.

Spring Boot Loader purpose

Spring Boot defines its own rules for executable JARs: third‑party JARs are placed under /lib, URLs use the custom jar:file:…!/ syntax handled by org.springframework.boot.loader.jar.Handler, and the main class is JarLauncher (or WarLauncher for WARs). All of this is assembled by the spring-boot-maven-plugin.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Spring BootClass Loaderexecutable JARJarLauncherMaven Plugin
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.