-1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Dragos Roban
  • 479
  • 2
  • 11
  • 20
  • 3
    Which “two principles” are you talking about? – Holger Dec 18 '20 at 10:06
  • @Holger I was talking about jigsaw vs jlink. I saw that jlink may be proper and suitable for what I am trying to do. Practically I need a smaller JRE just for my application. Jlink is the solution, but I am wondering how to generate those module-info.java files which contains the packages to import and export. – Dragos Roban Dec 18 '20 at 11:00
  • 1
    Neither “jigsaw” nor “jlink” is a principle. And since jlink is part of jigsaw, I still don’t understand what “jigsaw vs jlink” or “the differences … between these two principles” is supposed to mean. You can use [`jdeps`](https://docs.oracle.com/javase/9/tools/jdeps.htm#JSWOR690) to analyze dependencies, it even has e `--generate-module-info` option, but don’t ask us for a complete tutorial. – Holger Dec 18 '20 at 11:04
  • Man that's the answer I needed in the first place. I don't ask for full tutorial. jdeps will help me. And didn't know how jlink is part of jigsaw. So you could be nice to help me with this. That's why I quoted "priciples". I may sound stupid I know. Because it's an hour since I looked up into those terms. Be nicer. I don't ask for everything done. just some short explanation. I will research for the rest. Thanks. – Dragos Roban Dec 18 '20 at 11:13
  • 2
    No offense intended. We sometimes get confused by unclear question ourselves and think, we might have missed something. So we ask. Jigsaw is the [old project name](https://openjdk.java.net/projects/jigsaw/) under which the Java module system was developed. You don’t need to know it or use it. But if you encounter it, you can treat it as a synonym for the Java module system. – Holger Dec 18 '20 at 11:21
  • No problem. seems lik jlink will help me. Thank you for your time. :) – Dragos Roban Dec 18 '20 at 11:43
  • By the way, I think this is an interesting topic to discuss, I don't get why I have a "-1" there. :) Thanks for appreciation. – Dragos Roban Dec 22 '20 at 09:22
  • 1
    Don’t try to comprehend every vote. That won’t lead anywhere. – Holger Dec 22 '20 at 10:02

1 Answers1

2

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.

Benjamin Marwell
  • 1,173
  • 1
  • 13
  • 36
  • Thanks a lot for your answers. I will try to look up all the details. Seems like JLINK is the solution. A custom runtime image would help me here. I will come back with an answer as I implement what I need. And yes, I am using maven. Thank you. – Dragos Roban Dec 18 '20 at 11:42
  • How can I enable module-info.java creation on my modules in Intellij? Seems like if I create it manually it doesn't recognize it as a module description file. I have amazon correto 11. And the project is setup to use latest version of java. – Dragos Roban Dec 18 '20 at 14:49
  • 2
    Try Project Settings (Ctrl+Alt+Shift+S) and then select at least Java 9. Add a module-info.java file in the java root folder (may not reside in packages). You can then Alt-Enter on an import, a "add requires" should pop up. – Benjamin Marwell Dec 18 '20 at 17:37
  • Thanks for the tip. It's kinda messy over the project structure because I have two modules with the same package path so it collide somehow. I don't know if there is a trick for this. Plus on the 'requires' fileds it complains that the same package is from two dependencies. I think this would save me by excluding one of the dependencies from it's parents. For example for java.persistance comes from javax.persistance / jakarta.persistance. Dirty thing. Is there a proper fix for this? – Dragos Roban Dec 22 '20 at 08:47