r/java • • Nov 21 '20

Java Modules Cheat Sheet

https://nipafx.dev/build-modules/
113 Upvotes

44 comments sorted by

View all comments

42

u/lukaseder Nov 21 '20

This is missing the simplest of all cheats:

rm module-info.java

0

u/[deleted] Nov 21 '20

[deleted]

3

u/ObscureCulturalMeme Nov 22 '20

We have absolutely no use for them at work. We have to explicitly suppress all module warnings and open up everything to everything in order to make commercial third-party Cipher implementations work.

Eventually we'll have to adopt them in order to make jlink work. The first engineer who volunteered to learn modules ended up desperately searching for another job and then leaving for it, all within about four months. Nobody else cares enough to slog through the mess; the trade-off currently doesn't bring us enough.

3

u/pron98 Nov 22 '20

Note that encapsulation will be turned on in JDK 16: https://openjdk.java.net/jeps/396

You don't need to modularise your codebase, but you will need to resolve issues regarding dependencies that hack into the JDK (you'll need to request the vendors of the cipher suites you're using to fix their problems) or explicitly allow them.

1

u/ObscureCulturalMeme Nov 22 '20

Hopefully by then we'll have moved to jlink, and can simply choose whatever JDK to bundle up into an executable.

If not, it's likely the project will just be abandoned. The churn of "must work around someone else's fuckery simply to keep the code running" but without ever seeing new benefits is just exhausting.

1

u/pron98 Nov 22 '20

That's why encapsulation is important, and why the module system was added (among other reasons): To prevent libraries from tying themselves to specific implementation details and making your life hard, so that you won't have to work around their screwups anymore.

BTW, you don't need to modularise your app to use jlink.

1

u/ObscureCulturalMeme Nov 22 '20

To prevent libraries from tying themselves to specific implementation details and making your life hard, so that you won't have to work around their screwups anymore.

Yes, I realize that the future will be better. But the past is already here, and the future doesn't help us.

BTW, you don't need to modularise your app to use jlink.

That only means the executable includes the entirety of (what used to be called) the JRE, instead of the pieces of java.*/javax.* that we actually use. Our module-less experiment with jlink took 12 MB of class files and produced an .exe of nearly half a gigabyte.

1

u/pron98 Nov 22 '20 edited Nov 22 '20

That only means the executable includes the entirety of (what used to be called) the JRE

No, you can choose which modules to include in the runtime image. The difference is that if your application is modularised then this is done automatically, and if it isn't, you need to choose the modules manually (with --add-modules) but can use jdeps's --print-module-deps for assistance.

E.g.

jlink --output my-minimal-runtime --no-header-files --no-man-pages --add-modules java.base

will give you a runtime with just java.base, and that is under 40MB in total.

1

u/ObscureCulturalMeme Nov 22 '20

I know it says that on paper, but we got nothing but errors from jlink and jdeps. Googling the errors got us other people asking for help for the same things, and responses of "this is still new technology, wait for the next tools release".

I appreciate that you keep saying what should be possible, but right now it's been nothing but frustration and discouragement and a complete lack of useful up-to-date documentation. We just don't have the time or resources to fight through it blindly -- and I appreciate that no opensource project volunteers want to maintain or improve documentation in their limited free time, so I'm not looking for the docs to magically improve.

Maybe some future project of ours can use all these features from day one; I agree that sounds really pleasant.

2

u/pron98 Nov 23 '20

but we got nothing but errors from jlink and jdeps

That's surprising. What errors are you getting?

and a complete lack of useful up-to-date documentation

Up-to-date documenation is where it's always been: https://docs.oracle.com/en/java/javase/15/

What's missing?

and I appreciate that no opensource project volunteers

OpenJDK is open-source, but very few of the people working on it are volunteers. ~90% of the work is done by full-time Oracle engineers, and most of the rest is done by full-time engineers at Red Hat, SAP and some other companies. We may not have invested in the documentation as much as we'd like, but what, specifically, is missing here?

→ More replies (0)