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

What Are Modular JARs?

Understanding modular JARs as JAR files containing a module-info.class, distinguishing them from traditional JARs.

What Are Modular JARs?

You'll learn: How modular JARs differ from traditional JARs and what makes a JAR "modular" in the Java Platform Module System.

The Key Distinction

A modular JAR is simply a JAR file that contains a compiled module-info.class file at its root. This single file transforms an ordinary JAR into a module that participates in the Java Platform Module System (JPMS). Traditional JARs lack this descriptor and are treated as "unnamed modules" or placed on the classpath.

Think of it like this: a traditional JAR is like a box of components with no instruction manual—you can access everything inside, but there's no clear contract. A modular JAR includes that instruction manual (the module-info.class), explicitly declaring what the module provides, what it requires, and what it exposes to others.

What's Inside module-info.class?

The module-info.class is the compiled bytecode from your module-info.java file. It contains all your module declarations:

  • Module name (your module's identity)
  • requires directives (dependencies you need)
  • exports directives (packages you make visible)
  • opens directives (packages you allow reflection access to)
  • uses and provides clauses (service loading declarations)

Why It Matters

When the Java runtime encounters a modular JAR on the module path, it reads the module-info.class to understand the module's boundaries and relationships. This enables strong encapsulation, reliable configuration, and the ability to detect missing dependencies at startup rather than at runtime.

A traditional JAR on the classpath? The runtime treats all its public types as accessible to everyone—no boundaries, no explicit contracts.

Key Takeaway: A modular JAR is a JAR file containing module-info.class at its root, which transforms it from a simple archive into a self-describing module with explicit dependencies and encapsulation rules enforced by JPMS.