Java 9 has three ways to package compiled code in files:
JAR
JMOD
JIMAGE
JIMAGE is optimized for speed and space and used by the JVM at runtime so it makes sense why JIMAGE was introduced. JIMAGE files are not supposed to be published to maven repos or used at compile or link time.
The docs claim that JMOD can store native code and other things that can't be stored by JAR files and that developers can make and distribute their own JMOD files. The JDK ships with jmods/ directory containing all the modules of the JDK for users to depend on.
Questions:
Why did Java 9 introduce the JMOD file format?
Should a library author distribute a JMOD file or a JAR file or both?
Should jmod files be published to maven repos?
解决方案
Here are some quotes from JEP 261: Module System, which contains a section on JMOD files.
Why?
The new JMOD format goes beyond JAR files to include native code,
configuration files, and other kinds of data that do not fit
naturally, if at all, into JAR files.
and
The final format of JMOD files is an open issue, but for now it is
based on ZIP files.
Should a developer publish JMOD files?
Note that JMOD files appear to be a way to incorporate native code (among other things) at compile-time and link-time. From JEP 261:
JMOD files can be used at compile time and link time, but not at run
time.
(To be honest, I'm not sure how native code is published pre-JDK 9.) For the vast majority of developers (without native libraries or other corner-cases), we will merely publish modular jars.