Home >Java >javaTutorial >How to Resolve \'Unable to Derive Module Descriptor\' Errors for Auto-Generated Module Names in Java 9?
Unable to Derive Module Descriptor for Auto-Generated Module Names in Java 9?
In Java 9, a common issue arises when using the auto-generated module name for dependencies that contain reserved keywords such as "native." This can lead to errors like "module not found."
Understanding the Issue
Java 9 introduced the concept of modules, which allowed for encapsulation and isolation of code. Modules have unique names that must adhere to Java identifier rules. However, certain keywords, like "native," cannot be used as part of a module name.
Possible Workarounds
1. Using Automatic-Module-Name Manifest Entry
One solution is to add a "Automatic-Module-Name" manifest entry to the JAR file of the problematic dependency. This entry specifies a custom module name for the artifact, overriding the auto-generated one. For example, you could modify the manifest file of the Netty Epoll dependency to include:
<Automatic-Module-Name>netty.transport.epoll</Automatic-Module-Name>
2. Adding Module Declaration to JAR
Artifact owners can also add a module declaration using a "module-info.java" file to their JAR. This defines the module name explicitly, ensuring compatibility with Java 9's module system.
Alternative Naming Conventions
As per the Java specifications, module names must be valid package names. To accommodate cases where the Internet domain name of a dependency does not translate to a valid package name, the following conventions are suggested:
Note, however, that using underscores in module names is discouraged in Java 9 due to its status as a keyword.
The above is the detailed content of How to Resolve \'Unable to Derive Module Descriptor\' Errors for Auto-Generated Module Names in Java 9?. For more information, please follow other related articles on the PHP Chinese website!