Creating a modular JAR
Compiling modules into a class is good, but it is not suitable for sharing binaries and deployment. JARs are better formats for sharing and deployment. We can package the compiled module into JARs, and the JARs that contain module-info.class
at its top level are called modular JARs. In this recipe, we will look at how to create modular JARs, and we'll also look at how to execute the application, which is composed of multiple modular JARs.
Getting ready
We have seen and created a simple modular application in the Creating a simpler modular application recipe. In order to build a modular JAR, we will make use of the sample code available at Chapter03/3_modular_jar
. This sample code contains two modules: math.util
and calculator
. We will create modular JARs for both the modules.
How to do it...
- Compile the code and place the compiled classes in a directory, say,
mods
:
javac -d mods --module-source-path . $(find . -name *.java)
- Build a modular JAR for the
math.util...