r/java • • Jul 31 '26

Modular Uberjars

https://github.com/bowbahdoe/modular-uberjars
23 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/tkslaw Jul 31 '26

In theory you could use jmod format instead of jars for the dependencies right?

As far as I know, JMOD files can only be used at compile-time (javac, etc.) and link-time (jlink). They cannot be used at run-time (java).

I believe the main benefit of JMOD files is during link-time. For instance, any native libraries in the JMOD file are extracted and placed in the custom JRE such that they're easily loadable; no messing around with manual run-time extraction, system properties, and/or environment variables. Contrast that with using a JAR file that embeds the native library. In that case, the native library is considered to be a resource like everything else in the JAR file and will be embedded in the JRT image. The code would have to manually extract the native library at run-time before being able to load it.

2

u/bowbahdoe Aug 01 '26

All correct, but the format isn't so esoteric that you couldn't write your own class loader to pull from it (under the classes section it's basically just what a jar is) 

You could also include that hacky extraction at runtime bit inside the bootstrap. Combined with a dependency procurement step that splits the jmod across the module path and system library path... It's doable. 

Caveats obviously abound with signed jmods or ones using the hash modules feature.