Skip to content

IndexOutOfBoundsException when running a Spring Boot fat JAR with embedded dependency larger than 5.5GB #47663

@andres-orozco1

Description

@andres-orozco1

Known issue: #27900

Description:

I am encountering a critical issue when packaging and running a Spring Boot application that embeds a very large external JAR (~5.5GB)
At runtime, the application throws a java.lang.IllegalStateException caused by java.lang.NoClassDefFoundError for classes from the embedded JAR

This issue appears to be related to limitations in Spring Boot’s executable JAR classloader when dealing with very large embedded dependencies. Smaller embedded JARs do not cause this problem.

Spring Boot version: 3.3.x

Expected Behavior

Spring Boot should correctly load and run applications embedding large JAR dependencies without classloading errors.

Actual Behavior

The application fails at startup due to classloading errors originating from Spring Boot’s loader unable to process large embedded JAR files.

Workaround / Temporary Solution

To work around this issue, I unpack the large embedded JAR and include its contents directly inside the BOOT-INF/classes/ directory instead of embedding it as a nested JAR inside BOOT-INF/lib/. This is done by:

Marking the large JAR as compileOnly so it is not included automatically.

Excluding the JAR file from BOOT-INF/lib/ in the bootJar task.

Extracting the contents of the large JAR using zipTree and copying them into BOOT-INF/classes/.

This workaround allows Spring Boot’s classloader to load the classes properly and the application to run successfully.

tasks.bootJar {
    enabled = true
    archiveClassifier.set("")
    loaderImplementation.set(org.springframework.boot.loader.tools.LoaderImplementation.CLASSIC)

    val myJar = resolvedCompileOnly
        .firstOrNull { it.name.contains("myEmbedded5.5GB.jar") }
        ?: throw GradleException("myEmbedded5.5GB.jar not found in compileOnly")

    exclude("BOOT-INF/lib/myEmbedded5.5GB.jar")

    from(zipTree(myJar)) {
        into("BOOT-INF/classes/")
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions