The Automatic-Module-Name Manifest Entry
You'll learn how to give an automatic module a stable, predictable name instead of relying on the JAR filename.
When you learned how automatic modules are named from JAR filenames, you saw that the module name is derived by transforming the filename—stripping version numbers, replacing hyphens with dots, etc. This works, but it's fragile: renaming the JAR file changes the module name, breaking any requires declarations that depend on it.
The Automatic-Module-Name manifest attribute solves this problem by letting library authors explicitly declare the module name their JAR should use when placed on the module path.
How It Works
You add Automatic-Module-Name to your JAR's META-INF/MANIFEST.MF file:
Automatic-Module-Name: com.example.mylibrary
When the JAR is placed on the module path, the JPMS reads this manifest entry and uses com.example.mylibrary as the module name—regardless of the JAR filename. You could rename the file from mylibrary-1.0.jar to mylibrary-2.5.jar or even some-weird-name.jar, and the module name remains constant.
Why This Matters
Think of it like a domain name vs an IP address. The filename is like an IP address—it works but changes easily. The Automatic-Module-Name is like a stable domain name that always points to the same resource.
This is especially important for library maintainers who haven't fully modularized yet but want to support modular consumers. By specifying Automatic-Module-Name, you establish a naming contract that won't break when users upgrade library versions.
Key Takeaway:
The Automatic-Module-Name manifest entry lets you specify a stable, explicit module name for a JAR, protecting downstream consumers from module name changes caused by file renaming.