Home > Java > javaTutorial > How to Resolve Java 9 Module Dependency Issues with Auto-Generated Names Containing Reserved Keywords?

How to Resolve Java 9 Module Dependency Issues with Auto-Generated Names Containing Reserved Keywords?

Barbara Streisand
Release: 2024-11-28 15:02:10
Original
391 people have browsed it

How to Resolve Java 9 Module Dependency Issues with Auto-Generated Names Containing Reserved Keywords?

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:

  1. 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.

  2. 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:

  • Each component must be a valid Java identifier (excluding keywords).
  • If the domain name used for the module name contains special characters or keywords, it must be converted to an underscore.
  • If a component starts with a digit or other characters not allowed as the first character of an identifier, an underscore must be prefixed.

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
Copy after login

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!

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