It would be amazing if our modular JARs could be run with pre-JDK 9 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 its root. We will see how to do so in this recipe.
For this recipe, we will need a modular jar and a non-modular application. Our modular code can be found at chp3/4_modular_jar_with_pre_java9/math.util
(this is the same math.util
module that we created in our recipe, Creating a simple modular application). 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 chp3/4_modular_jar_with_pre_java9
, which...