Course contentsShow
← Java
Lesson 2515 of 2,87047. Java Platform Module System (JPMS)Free lesson

Modular JARs vs Non-Modular JARs at Runtime

Understanding runtime behavior when mixing modular and non-modular JARs, and automatic module conversion.

Modular JARs vs Non-Modular JARs at Runtime

You'll learn: How the JVM handles the runtime interaction between modular and non-modular JARs, and the concept of automatic module conversion.

The Runtime Challenge

When you deploy a Java application, you might have a mix of modular JARs (with module-info.class) and traditional non-modular JARs on your paths. The JVM needs a strategy to make them work together without breaking existing code.

Automatic Modules: The Bridge

When a non-modular JAR is placed on the module path (not classpath), the JVM automatically converts it into an automatic module. Think of it like giving a passport to someone who crossed a border—they're allowed in, but with special rules.

Key Characteristics of Automatic Modules:

  • Module name derived: From the JAR filename (or Automatic-Module-Name in MANIFEST.MF if present)
  • Exports everything: All packages are implicitly exported
  • Reads all modules: Automatically requires every other module it can see
  • Reflection-friendly: All packages are open for deep reflection

This means your old, pre-JPMS libraries can still participate in the module system without modification.

The Four Runtime Scenarios

  1. Modular JAR on module path: Normal modular behavior—strong encapsulation applies
  2. Non-modular JAR on module path: Becomes an automatic module
  3. Non-modular JAR on classpath: Joins the "unnamed module" (pre-JPMS behavior)
  4. Modular JAR on classpath: Module descriptor is ignored; treated as non-modular

Why This Matters

This dual-mode system enables gradual migration. Your fully modular code can depend on automatic modules (legacy libraries), allowing you to modernize incrementally rather than rewriting everything at once.

Key Takeaway: Non-modular JARs on the module path become automatic modules that export all packages and read all other modules, bridging the gap between legacy code and JPMS while maintaining compatibility.