Blog Posts BPMN DMN

Custom Layered Immutable Spring Boot Kie Server

Blog: Drools & jBPM Blog

Layered Immutable Spring Boot Kie Server
“Uncommon thinkers reuse what common thinkers refuse” (J.R.D. Tata)

When creating an image for an immutable Spring Boot Kie Server application, it is possible to split up the files and folders belonging to the fat-jar into different layers.

Main advantages of this approach are:

  1. Libraries, code, and resources are grouped into layers based on the likelihood to change between builds. This reduces the image generation time.
  2. Layers downloaded once (saving disk space and bandwidth) and reused for other images.
  3. Execution over the unzipped classes is a little bit faster than launching the fat-jar: java -jar app.jar

Considering all these points, it is completely meaningful to layer the immutable Spring Boot Kie Server -isolating the KJARs into a new custom layer- as business assets in KJARs are more likely to change.

Packaging Spring Boot Kie Server with layers

The spring-boot-maven-plugin is in charge of creating the immutable fat-jar containing all the KJAR files and their dependencies. For triggering this process, just add the following properties to the Spring Boot file:


Next, we have to enable the layers into the pom.xml, pointing out to the configuration file layers.xml where we define how the folders, files, and resources are separated into different layers and the order of them.


In this layers.xml file, we define the following layers in this order (the first four are default ones, adding custom kjars layer at the end, as it is the more likely to change during application lifetime):

<layers xmlns=""
        <into layer="spring-boot-loader">
        <into layer="kjars">
        <into layer="application" />
        <into layer="snapshot-dependencies">
        <into layer="dependencies">
            <includeModuleDependencies />

Finally, once we have the configuration of the pom.xml and layers.xml set up, we may launch the package process by invoking to the maven command:

$ mvn clean package -DskipTests

Spring Boot Kie Server Layers inspect

We can check out the result of this layering process using the property jarmode=layertools with the list argument for the generated fat-jar:

$ java -Djarmode=layertools -jar target/immutable-springboot-kie-server-1.0.0.jar list


Our custom kjars layer is the last one as defined in the layerOrder node of layers.xml file.

Another interesting file we may check out is the layers.idx where packaging information (separated folders and layer order) is stored.

$ cat application/BOOT-INF/layers.idx 
- "dependencies":
  - "BOOT-INF/lib/"
- "spring-boot-loader":
  - "org/"
- "snapshot-dependencies":
- "application":
  - "BOOT-INF/classes/"
  - "BOOT-INF/classes/org/"
  - "BOOT-INF/classes/"
  - "BOOT-INF/classpath.idx"
  - "BOOT-INF/layers.idx"
  - "META-INF/"
- "kjars":
  - "BOOT-INF/classes/KIE-INF/"

Moreover, we can extract the layers again using the property jarmode=layertools with the extract argument for the generated fat-jar:

$ java -Djarmode=layertools -jar target/immutable-springboot-kie-server-1.0.0.jar extract

$ tree kjars 
    └── classes
        └── KIE-INF
            └── lib
                ├── kjar-sample-1.0.0.jar
                ├── kjar-sample-1.1.0.jar
                └── other-kjar-1.0.0.jar

4 directories, 3 files

We can use this utility in the Dockerfile for easily extracting the layers of the fat-jar and dockerize our immutable Spring Boot Kie Server application.

Layered Dockerfile

We can define a multi-stage Dockerfile to take advantage of this layering and build the image:

FROM openjdk:8-slim as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} immutable-springboot-kie-server-1.0.0.jar
RUN java -Djarmode=layertools -jar immutable-springboot-kie-server-1.0.0.jar extract

FROM openjdk:8-slim
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
COPY --from=builder application/kjars/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

TIP: You may consider any other layering depending on the likelihood of changes for the grouped libraries, code, and resources.

Happy layering!!

The post Custom Layered Immutable Spring Boot Kie Server appeared first on KIE Community.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples