Aka: don’t pack fat jars into your container

This post assumes you are using JDK 15

To run a java program from an image, you still need to provide the fat jar in the container.
You then want to extract the fat jar (jar -extract or unzip) into a separate folder.
You should now have a “BOOT-INF” “META-INF” and maybe other folders depending on your codebase.

Skip extracting the namespace if you already know the exact namespace of your main class.

Find the textfile “MANIFEST.MS” in META-INF and open it up, check to find the “MainClass” definition at the end of the file, keep this value in mind.
If your java project uses the spring boot framework (at least at the 2.x versions) you have to substitute the main class found in the MANIFEST.MS with

This is because the spring framework uses its own means and structure to pack jar files and bootstraps them with their propertieslauncher.

Now the only step left to do is to call the entrypoint correctly.
ENTRYPOINT java namespace.to.my.mainclass

An example for a correctly build dockerfile calling such a jar looks like so:

FROM adoptopenjdk15_hotspot as builder
WORKDIR /extracted_jar
COPY hostDir/myjar.jar ./
RUN jar -xf myjar.jar
ENTRYPOINT java my.main.class