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

The module-info.java File: Location and Purpose

Learn where module-info.java must be placed in your project structure and its role in defining module boundaries.

The module-info.java File: Location and Purpose

You'll learn where to place module-info.java in your project and understand its role as the gatekeeper of module boundaries.

Now that you know JPMS exists, you need to understand its central artifact: the module-info.java file. This special file is your module's declaration of identity—it defines what your module is called, what it exposes to others, and what it depends on.

Where Does It Go?

The module-info.java file must be placed at the root of your source directory, alongside your package folders. If your project structure looks like this:

src/
  module-info.java          ← Here, at the root
  com/
    myapp/
      Main.java
      util/
        Helper.java

The module-info.java sits at the same level where your top-level packages begin. This positioning is mandatory—the compiler looks for it there to understand your module's structure.

What Is Its Purpose?

Think of module-info.java as a border control checkpoint for your module. It explicitly declares:

  • Your module's name (its global identifier)
  • What packages you export (what the outside world can access)
  • What other modules you depend on (your required imports)
  • Services you provide or consume (more advanced scenarios)

Without this file, your code is just a collection of packages on the traditional classpath—no encapsulation boundaries, no explicit dependencies. With it, you've created a proper JPMS module with strong encapsulation.

The file uses special keywords you'll learn next, but its location never changes: always at the source root, always named module-info.java.

Key Takeaway: The module-info.java file must reside at your source root and serves as your module's boundary definition, declaring its name, exports, and dependencies.