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

What Are Automatic Modules?

Understanding automatic modules as a bridge between legacy JARs and the module system, and why they exist.

What Are Automatic Modules?

You'll learn: How automatic modules bridge the gap between legacy JARs and the module system, allowing gradual migration.

The Bridge Between Two Worlds

When you place a non-modular JAR (one without module-info.java) on the module path instead of the classpath, the JVM automatically treats it as an automatic module. This is JPMS's compatibility mechanism—a bridge that lets modular code depend on legacy libraries that haven't been converted to explicit modules yet.

Why Automatic Modules Exist

Imagine you're migrating your application to JPMS using the bottom-up strategy, but one of your dependencies hasn't released a modular version yet. Without automatic modules, you'd be stuck—unable to use the module path at all. Automatic modules solve this by:

  1. Generating a module name from the JAR filename (e.g., commons-lang3-3.12.0.jar becomes module commons.lang3)
  2. Exporting all packages to other modules automatically
  3. Reading all other modules (both explicit and automatic)
  4. Granting reflective access to all packages by default

This means you can requires commons.lang3; in your module-info.java even though that JAR doesn't have its own module descriptor.

The Trade-Off

Automatic modules sacrifice the strong encapsulation and explicit dependencies that make JPMS powerful. They're a temporary migration tool, not a permanent solution. Think of them as training wheels: helpful while learning, but you'll want explicit modules eventually for reliability and security.

Key Takeaway:
Automatic modules let non-modular JARs work on the module path by generating module names and exposing everything—they're essential for gradual migration but lack the encapsulation benefits of explicit modules.