Description
I'm working on a small Spring Boot app and would like to create a self-contained application image with jlink.
- Java 16
- Spring Boot 2.4.2
What I tried
I tried several different approaches, but all of them failed.
Proper module-info.java
My first try was to create my own module-info.java
, but that gets moved into the fat JAR's root without further changes. That means it still lists the Spring modules as dependencies, but since they're now included in the JAR, they won't be found on any module path and thus jlink refuses to create the image.
There are hacky ways around that (creating empty JARs with the right module names), but I suspect this would lead to the same problems as the next approach.
Using Moditect on fat JAR
With Moditect, I can inject a module declaration into the fat JAR. That's actually pretty easy because there are no external dependencies.
Unfortunately, jlink refuses to create the image because of the BOOT-INF
folder:
[INFO] --- moditect-maven-plugin:1.0.0.RC1:create-runtime-image (create-runtime-image) @ calendar ---
[ERROR] Error: java.lang.IllegalArgumentException: BOOT-INF.classes.dev.nipafx.calendar.spring:
Invalid package name: 'BOOT-INF' is not a Java identifier
(I expect the approach above would fail at this step as well even if the problem with the module descriptor could be solved.)
Using Moditext on all JARs
I considered configuring Spring Boot to not create a fat JAR. My goal was to then use Moditect to create a module descriptor for all (transitive) dependencies of the app and thus use jlink on all of them. This may work, but due to the sheer number of dependencies and my (possibly faulty) impression that I need to configure the declaration for all of them. That's a lot of work.
Conclusion
It seems that there's no (good) way to create an application image that contains a Spring Boot app. That's a shame because that's a pretty nifty feature. It would be nice if Spring Boot offered at least one path to application image heaven. 😁