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

Platform Modules: Requiring JDK Modules

Discover how to declare dependencies on platform modules like java.sql, java.xml, and java.logging.

Platform Modules: Requiring JDK Modules

What you'll learn: How to declare dependencies on JDK platform modules like java.sql, java.xml, and java.logging in your modular applications.

Why Platform Modules Matter

Since Java 9, the JDK itself is modularized. Not every application needs every JDK API—if you're building a simple console app, why load the entire SQL or XML stack? The module system now makes these dependencies explicit rather than assuming everything is always available.

Common Platform Modules

The JDK ships with dozens of platform modules. Here are the most frequently used:

  • java.base — Always available implicitly (String, Object, Collections, etc.)
  • java.sql — JDBC and database APIs
  • java.xml — XML parsing, DOM, SAX
  • java.logging — java.util.logging framework
  • java.desktop — Swing, AWT
  • java.net.http — HTTP client (Java 11+)

Declaring Dependencies on Platform Modules

Use the requires directive just like you would for application modules:

module com.myapp.database {
    requires java.sql;
    requires java.logging;
}

This tells the module system: "My module needs JDBC and logging APIs." At compile and runtime, these platform modules will be resolved and loaded.

When You Need Them

If your code references classes like java.sql.Connection or java.util.logging.Logger, you must declare the corresponding platform module. Without it, the compiler will report package accessibility errors—even though these are standard JDK classes.

Key Insight

Platform modules aren't just documentation—they're enforced boundaries. If you forget requires java.xml but use XML APIs, your module won't compile.

Key Takeaway:
Explicitly declare dependencies on JDK platform modules like java.sql and java.logging using requires in your module descriptor to access their APIs.