Home >Java >javaTutorial >How to Resolve \'Unable to Derive Module Descriptor\' Errors for Auto-Generated Module Names in Java 9?

How to Resolve \'Unable to Derive Module Descriptor\' Errors for Auto-Generated Module Names in Java 9?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-25 03:43:12647browse

How to Resolve

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:

  • Convert hyphens or other special characters to underscores.
  • Append an underscore to keywords.
  • Prefix components starting with disallowed characters with an underscore.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn