Using a module JAR with pre-Project Jigsaw JDK applications
It would be amazing if our modular JARs could be run with pre-Project Jigsaw JDK applications. This way, we will not be concerned with writing another version of our API for pre-JDK 9 applications. The good news is that we can use our modular JARs just as if they were ordinary JARs, that is, JARs without module-info.class
at their root. We will see how to do so in this recipe.
Â
Getting ready
For this recipe, we will need a modular jar and a non-modular application. Our modular code can be found at Chapter03/4_modular_jar_with_pre_java9/math.util
 (this is the same math.util
module that we created in our Creating a simple modular application recipe). Let's compile this modular code and create a modular JAR by using the following commands:
javac -d classes --module-source-path . $(find math.util -name *.java)
mkdir mlib
jar --create --file mlib/math.util.jar -C classes/math.util .
We have also provided a jar-math.bat
script at Chapter03...