Jorge's Notebook

Jorge's Notebook

Wellcome! This is a multi-lengual notebook. You'll read some geeky things here. I hope you enjoy it.

How to Create a Small JRE for your Microservices

Here, you will learn about how to create a small JRE for your microservices.

Jorge Andreu Calatayud

2-Minute Read

In this post you’ll learn about how to create a small JRE for your microservices.

Firstly you are going to need a java project. So you have to go to your root folder project. When you are there you have to run the next command:

jdeps --list-deps {{jar-name}}.jar

This command is going to give us a list of modules that we are using in our java microservice. I’m running this again to hello-world java service, so I’m not going to have that many dependencies. My output was the following one:

$ jdeps --list-deps hello-0.0.1-SNAPSHOT.jar
  not found

The previous output is going to tell us which modules we are using in the jar. Now we need to crate our JRE.

$ jlink --module-path /opt/java/jmods --compress=2 --strip-debug \
  --no-header-files --no-man-pages \
  --add-modules java.base,java.logging --output /opt/jlink 

Now, we have our runtime in /opt/jlink folder that we can use to run our application and this folder is going to be around 30 Mb instead of 240 Mb which is the normal size of the JDK.

Nowadays we need to create automated tasks to make everything easier. These steps are really easy to set in a Dockerfile. If you do this you could create an image that is smaller than 100 Mb, maybe a bit more if you have a lot of dependencies. It may look difficult but it’s not. I’ll try to create another post showing how to do this in an automated way with the dockerfile. I hope you like this post so far and I’ll see you in the next one.

comments powered by Disqus

Recent Posts



In this Notebook I’ll post about my knowledges, and somethings that I’ll discover while I’m working. I won’t post all days because it’s a impossible. I’ll try to post one per week or at least one per month. If you like my posts stay tune becuase I’ll start a youtube channel guess how is gonig to be the name?…jorge's Notebook!.