Unable to Resolve Module Dependency for Auto-Generated Names in Java 9?
This issue arises when a dependency with an auto-generated module name contains the keyword "native," which is reserved in Java 9. Consequently, it becomes impossible to add it as a dependency to the module descriptor.
Solution:
To resolve this issue, two primary approaches can be considered:
Add Automatic Module Name Attribute:
Artifact owners can package a META-INF/MANIFEST.MF file with the artifact that specifies the Automatic-Module-Name attribute. This attribute defines the module name to be used by the module descriptor. By setting the Automatic-Module-Name to a valid name (excluding "native"), the issue can be resolved.
Add Module Declaration to JAR:
Artifact owners can add module declarations using module-info.java to their JAR files. This allows them to specify the module name explicitly, thereby avoiding the auto-generated names. However, this approach requires a gradual migration, as libraries and frameworks adopt it bottom-up.
Module Descriptor Specifications:
According to the Java 9 module declaration specifications, a module name consists of one or more Java identifiers separated by periods. This means that module names must adhere to the following rules:
Note on Underscore in Java 9:
While underscores are typically allowed as part of module names, it is important to note that underscore is now a keyword in Java 9. Therefore, identifiers containing an underscore as the initial character must be avoided. For example:
int _native; // Works fine int _; // Causes an error in Java 9
The above is the detailed content of How to Resolve Java 9 Module Dependency Issues with Auto-Generated Names Containing Reserved Keywords?. For more information, please follow other related articles on the PHP Chinese website!