Book Image

Java 9 Cookbook

By : Mohamed Sanaulla, Nick Samoylov
Book Image

Java 9 Cookbook

By: Mohamed Sanaulla, Nick Samoylov

Overview of this book

<p>Java is an object-oriented programming language. It is one of the most widely accepted languages because of its design and programming features, particularly in its promise that you can write a program once and run it anywhere.</p> <p>This cookbook offers a range of software development examples in simple and straightforward Java 9 code, providing step-by-step resources and time-saving methods to help you solve data problems efficiently. Starting with the installation of Java, each recipe addresses a specific problem, with a discussion that explains the solution and offers insight into how it works.</p> <p>We cover major concepts such as Project Jigsaw and various tools that will enable you to modularize your applications. You will learn new features in the form of recipes that will make your applications modular, secure, and fast.</p>
Table of Contents (22 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Using a module JAR with pre-JDK 9 applications


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.

Getting ready

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...