Dragos Roban
Dragos Roban

Reputation: 599

Jigsaw / Jlink for modular Java projects to minimize JRE size

I am trying to understand the differences or the associations between these two principles / feature for Java modular projects.

I am trying to minimize the JRE size by reduce the use of the external libraries / modules.

In order to do that, I made some quick research and I found these two "principles" that may help me.

Now, I don't understand if these two things are different or if they link to one another somehow. How should I use these to reach my goal? Can you please specify what would be the best solution for me? In the module-info.java do I have to specify manually what do I need?

Is there a possibility to generate the module-info.java files? (I guess not but I am just asking). Can I use it with JDK Amazon Correto 11?

Upvotes: -1

Views: 777

Answers (1)

Benjamin Marwell
Benjamin Marwell

Reputation: 1246

you actually posted multiple questions.

I am trying to minimize the JRE size by reduce the use of the external libraries / modules.

Having fewer dependencies is always a good goal. jigsaw/JPMS will not help you with that. On the contrary: In fact you could end up with multiple versions of the same dependency, which wasn’t possible before.

Hint: JLink and JIGSAW/JPMS will not help you with reducing your dependencies.

How should I use these to reach my goal?

If your goal is to have a stripped-down JVM shipped with your application, you should look into the jlink binary, which is part of the JDK since Java 9.

If you are using maven, you could invoke it by using the maven-jlink-plugin. There are similar plugins for gradle and even for maven (e.g. javafx-specific plugins).

Can you please specify what would be the best solution for me?

That is something we cannot answer. YMMV – maybe quarkus is worth looking at as well, which creates native images (yes, os- and arch dependent native binaries).

In the module-info.java do I have to specify manually what do I need?

Yes, for your modules. You can use moditect if you use maven to inject a module-info.class file into your dependencies, at least if you are using maven as a build system.

Is there a possibility to generate the module-info.java files? I guess not but I am just asking)

Already answered in the comments, yes, by using jdeps.

Can I use it with JDK Amazon Correto 11?

Yes, they also ship both jlink and jdeps.

Upvotes: 2

Related Questions