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

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

Susan Sarandon
Release: 2024-11-25 03:05:18
Original
1032 people have browsed it

How to Resolve

Unable to derive module descriptor for auto-generated module names in Java 9

When using Java 9, you may encounter an error when trying to add a dependency with an auto-generated module name containing a reserved keyword, such as "native". This error occurs because Java 9 module names must follow specific naming conventions, and "native" is not a valid Java identifier.

One approach to solving this is to modify the dependency's JAR file by adding a "META-INF/MANIFEST.MF" file with an "Automatic-Module-Name" attribute. This attribute specifies the module name to be used when the JAR is converted to an automatic module.

For example:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-transport-native-epoll</artifactId>
    <version>${netty.version}</version>
    <classifier>${epoll.os}</classifier>
</dependency>

// Add a manifest file to the dependency's JAR:
<manifestEntries>
    <Automatic-Module-Name>netty.transport.epoll</Automatic-Module-Name>
</manifestEntries>
Copy after login

Alternatively, artifact owners can add module declarations to their JAR using "module-info.java" files. These declarations explicitly define the module name and its dependencies, which can help address the issue with invalid module names. However, this approach requires collaboration with the owners of affected libraries.

According to the Java Module System specifications, module names should follow these naming conventions:

  • Module names must consist of one or more Java identifiers separated by "." tokens.
  • Package names can be used as module names if they follow the same naming rules, with certain exceptions for domain names.
  • If the domain name contains special characters or keywords, it should be converted into an underscore or appended with an underscore.
  • Leading digits are not allowed in module names, and underscores can be used as prefixes to avoid this.

Remember that using underscores in Java 9 can be tricky, as they are considered keywords. As such, avoid using "native" or "default" as module names or package names.

The above is the detailed content of How to Resolve \'Unable to Derive Module Descriptor\' Errors in Java 9 with Auto-Generated Module Names?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template