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>
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:
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!