Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize JVM modules using jlink for a fat Jar file

One for the coolest feature of JDK9 is jlink that makes a small optimized version of the JVM to run the application which is pretty useful especially to run the app in a container like a docker one. However, it's not very simple to just pass the JAR file you have and get an optimized runtime to run it.

Like I use Gradle and create a fat jar file (all the dependencies in a single jar file), and I just simply want to use this jar file to generate the JVM for it? Any solution?

like image 375
user1079877 Avatar asked Nov 06 '25 06:11

user1079877


1 Answers

Use JDeps to analyze your project's dependencies:

jdeps --list-deps app.jar

Then extract all platform modules (those starting with java. or jdk.) from that list and feed them into jlink:

jlink --add-modules $REQUIRED-PLATFORM-MODULES --output jdk-for-app

To verify:

jdk-for-app/bin/java --list-modules

This includes all platform modules you determined as well as their dependencies.

like image 124
Nicolai Parlog Avatar answered Nov 08 '25 11:11

Nicolai Parlog