How JARs Become Automatic Modules
You'll learn: how placing a non-modular JAR on the module path transforms it into an automatic module—no code changes required.
The Automatic Conversion Process
When you place a traditional, non-modular JAR file on the module path (using --module-path or -p), the JVM automatically treats it as a module. This happens without requiring any module-info.java file inside the JAR.
Think of it like this: the module system acts as a friendly adapter, wrapping your old JAR in module clothing so it can participate in the modular world. The JAR doesn't know it's now a module—it just works.
What Happens During Conversion
When the JVM encounters a non-modular JAR on the module path:
- Module name generation: The system derives a module name from the JAR filename (stripping version numbers and normalizing characters)
- Implicit exports: All packages in the JAR are automatically exported
- Implicit requires: The automatic module gains
requires transitiveto all other modules it can see - Full accessibility: The module is opened for reflection to all other modules
Why This Matters
This automatic conversion is crucial for migration. You can start using the module path even when your dependencies haven't been modularized yet. The automatic module acts as a bridge between the modular and non-modular worlds.
For example, placing commons-lang3-3.12.0.jar on the module path creates an automatic module that can be referenced by explicit modules using requires commons.lang3; (the derived module name).
Key Takeaway: Placing any JAR on the module path automatically converts it into an automatic module with full exports and requires, enabling gradual migration to JPMS without forcing all dependencies to modularize simultaneously.