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

Modular JARs on the Module Path

Placing modular JARs on the module path using --module-path and how the module system resolves them.

Modular JARs on the Module Path

You'll learn: How to place modular JARs on the module path so the Java module system can discover and resolve them properly.


The Module Path vs Classpath

When working with JPMS, you use the module path instead of the traditional classpath. The module path is where you tell the Java runtime and compiler to look for modules. When you place a modular JAR on the module path, the module system reads its module-info.class, discovers its name, dependencies (requires), and exported packages, then builds a module graph.

Think of it like this: The classpath was a jumbled pile of classes where everything was visible to everything. The module path is an organized library catalog where each module declares exactly what it needs and what it shares.

Using --module-path

You specify the module path with the --module-path (or -p) option:

# Compiling with modules on the module path
javac --module-path mods -d out --module-source-path src -m mymodule

# Running with modules on the module path
java --module-path mods -m mymodule/com.example.Main

You can list multiple directories or JARs, separated by the platform path separator (: on Linux/Mac, ; on Windows):

java --module-path lib:mods:other-libs -m mymodule/com.example.Main

How Resolution Works

When you specify --module-path, the module system:

  1. Scans each location for modular JARs and exploded module directories
  2. Reads each module-info.class to identify module names
  3. Builds the module graph by resolving requires dependencies
  4. Validates that all required modules are present and acyclic

If a required module is missing, you'll get a clear error at startup—no more ClassNotFoundException at random runtime moments!

Key Takeaway: Use --module-path (or -p) to tell Java where your modular JARs live; the module system then reads their descriptors and resolves dependencies into a validated module graph before your application even starts.