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

Automatic Module Naming from JAR Filename

Understanding how module names are derived from JAR filenames by removing version numbers and converting to valid names.

Automatic Module Naming from JAR Filename

What you'll learn: How the Java module system automatically generates valid module names from JAR filenames when no explicit module descriptor exists.

When you place a non-modular JAR on the module path, it becomes an automatic module. But how does JPMS know what to call it? The system derives a module name directly from the JAR filename using a predictable transformation process.

The Naming Algorithm

The module system follows these steps to convert a JAR filename into a valid module name:

  1. Remove the .jar extension – commons-lang3-3.12.0.jar becomes commons-lang3-3.12.0
  2. Strip version suffixes – Numbers and trailing separators at the end are removed: commons-lang3-3.12.0 becomes commons-lang3
  3. Replace invalid characters with dots – Any character that isn't alphanumeric or a dot is converted to a dot: hyphens become dots, so commons-lang3 becomes commons.lang3
  4. Remove duplicate dots – Multiple consecutive dots collapse to one
  5. Remove leading/trailing dots – Clean up the edges

Example Transformations

  • guava-31.1-jre.jar → guava
  • jackson-databind-2.13.0.jar → jackson.databind
  • my_library-1.0-SNAPSHOT.jar → my.library

Why This Matters

These automatic names are what you'll use in requires directives when depending on automatic modules. If the filename is messy or changes between versions, the derived module name changes too—which can break your module declarations.

Key Takeaway: Automatic module names are derived from JAR filenames by removing version numbers, converting non-alphanumeric characters to dots, and cleaning up the result—making filename consistency crucial for stable module dependencies.