Author(s): Sander Mak, Paul Bakker
Edition: 1
Publisher: O'Reilly
Year: 2017
Language: English
Tags: java module modular modularity
Foreword
Preface
Who Should Read This Book
Why We Wrote This Book
Navigating This Book
Using Code Examples
Conventions Used in This Book
O’Reilly Safari
How to Contact Us
Acknowledgments
I. Introduction to the Java Module System
1. Modularity Matters
What Is Modularity?
Before Java 9
JARs as Modules?
Classpath Hell
Java 9 Modules
2. Modules and the Modular JDK
The Modular JDK
Module Descriptors
Readability
Accessibility
Implied Readability
Qualified Exports
Module Resolution and the Module Path
Using the Modular JDK Without Modules
3. Working with Modules
Your First Module
Anatomy of a Module
Naming Modules
Compilation
Packaging
Running Modules
Module Path
Linking Modules
No Module Is an Island
Introducing the EasyText Example
A Tale of Two Modules
Working with Platform Modules
Finding the Right Platform Module
Creating a GUI Module
The Limits of Encapsulation
Interfaces and Instantiation
4. Services
Factory Pattern
Services for Implementation Hiding
Providing Services
Consuming Services
Service Life Cycle
Service Provider Methods
Factory Pattern Revisited
Default Service Implementations
Service Implementation Selection
Service Type Inspection and Lazy Instantiation
Module Resolution with Service Binding
Services and Linking
5. Modularity Patterns
Determining Module Boundaries
Lean Modules
API Modules
What Should Be in an API Module?
Implied Readability
API Module with a Default Implementation
Aggregator Modules
Building a Facade over Modules
Safely Splitting a Module
Avoiding Cyclic Dependencies
Split Packages
Breaking Cycles
Optional Dependencies
Compile-Time Dependencies
Implementing Optional Dependencies with Services
Versioned Modules
Module Resolution and Versioning
Resource Encapsulation
Loading Resources from a Module
Loading Resources Across Modules
Working with ResourceBundles
6. Advanced Modularity Patterns
Strong Encapsulation Revisited
Deep Reflection
Open Modules and Packages
Dependency Injection
Reflection on Modules
Introspection
Modifying Modules
Annotations
Container Application Patterns
Layers and Configurations
Classloading in Layers
Plug-in Architectures
Container Architectures
Resolving Platform Modules in Containers
II. Migration
7. Migration Without Modules
The Classpath Is Dead, Long Live the Classpath
Libraries, Strong Encapsulation, and the JDK 9 Classpath
Compilation and Encapsulated APIs
Removed Types
Using JAXB and Other Java EE APIs
The jdk.unsupported Module
Other Changes
8. Migration to Modules
Migration Strategies
A Simple Example
Mixing Classpath and Module Path
Automatic Modules
Open Packages
Open Modules
VM Arguments to Break Encapsulation
Automatic Modules and the Classpath
Using jdeps
Loading Code Dynamically
Split Packages
9. Migration Case Study: Spring and Hibernate
Getting Familiar with the Application
Running on the Classpath with Java 9
Setting Up for Modules
Using Automatic Modules
Java Platform Dependencies and Automatic Modules
Opening Packages for Reflection
Fixing Illegal Access
Refactor to Multiple Modules
10. Library Migration
Before Modularization
Choosing a Library Module Name
Creating a Module Descriptor
Updating a Library with a Module Descriptor
Targeting Older Java Versions
Library Module Dependencies
Internal Dependencies
External Dependencies
Targeting Multiple Java Versions
Multi-Release JARs
Modular Multi-Release JARs
III. Modular Development Tooling
11. Build Tools and IDEs
Apache Maven
Multimodule Projects
EasyText with Apache Maven
Running a Modular Application with Apache Maven
Gradle
IDEs
12. Testing Modules
Blackbox Tests
Blackbox Tests with JUnit
Whitebox Tests
Test Tooling
13. Scaling Down with Custom Runtime Images
Static Versus Dynamic Linking
Using jlink
Finding the Right Service Provider Modules
Module Resolution During Linking
jlink for Classpath-Based Applications
Reducing Size
Improving Performance
Cross-Targeting Runtime Images
14. A Modular Future
OSGi
Java EE
Microservices
Next Steps
Index