Known issue: https://github.com/spring-projects/spring-boot/issues/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/")
}
}
Comment From: wilkinsona
Thanks for the report. Spring Boot 3.3.x is no longer supported. If you can reproduce the problem with Spring Boot 3.4.x or later and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue. It would also be useful to see the full stack trace of the IndexOutOfBoundsException.