Building a modular JAR file
We've looked at creating complete modular runtime images and learned about the advantages of the linking process, but sometimes that may not be what you want. Suppose you are a library developer and you just want to bundle a single utility module as a jar file. When building a jar file from a module, you have an option of creating a modular JAR file. A modular jar file is just like any other jar file, but with the module-info.class
file in the root directory. You can use this to distribute compiled modules as a single file instead of the whole module folder. You can drop a modular JAR file in a module path when running the java
command, and it behaves just like the compiled module folders that we've been dealing with.
To illustrate this, let's replace a couple of modules in the out
folder of the address book application with modular JAR files.
The way to create a modular JAR file is by using the jar
utility. In order to convert the packt.contact
module into a modular...