无法在Java 9中为自动生成的模块名称派生模块描述符? [英] Unable to derive module descriptor for auto generated module names in Java 9?

查看:1337
本文介绍了无法在Java 9中为自动生成的模块名称派生模块描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目依赖于Netty Epoll传输。这是依赖:

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

此依赖项的自动生成模块名称为:

  netty.transport.native.epoll 

由于Java 9中保留了 native 关键字,因此无法将此模块作为依赖项添加到我的项目中:

 模块核心{
需要netty.transport.native.epoll;
}

由于:

 找不到模块:netty.transport。< error> 

此外,jar工具 - describe-module 报告以下内容:


无法导出模块描述符:
netty-transport-native-epoll-4.1.17。 Final-SNAPSHOT-linux-x86_64.jar
netty.transport.native.epoll:模块名称无效:'native'不是
Java标识符


有没有解决方法? (当然,除了发布正确的网络工件)。



  int _; //将基于JDK9 
int _native在javac上抛出错误; //工作正常


My project depends on Netty Epoll transport. Here is dependency:

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

The auto-generated module name for this dependency is:

netty.transport.native.epoll

And as the native keyword is reserved in Java 9 I can't add this module as a dependency to my project:

module core {
    requires netty.transport.native.epoll;
}

Due to:

module not found: netty.transport.<error>

Additionally the jar tool --describe-module reports the following:

Unable to derive module descriptor for: netty-transport-native-epoll-4.1.17.Final-SNAPSHOT-linux-x86‌_64.jar netty.transport.native.epoll: Invalid module name: 'native' is not a Java identifier

Are there any workarounds? (except "release correct netty artifact", of course).

EDIT:

As the quick fix for maintainers - you can add next line to build:

<manifestEntries>
   <Automatic-Module-Name>netty.transport.epoll</Automatic-Module-Name>
</manifestEntries>

解决方案

Well the solution to this seems to be:-

  • renaming the artifact itself (might not be preferred by all owners)

    OR

  • Another way possible to uninterruptedly using the same artifact name with a new(different) module name could be by packaging META-INF/MANIFEST.MF of the artifact with an attribute Automatic-Module-Name which governs the name of the module to be used by the module descriptor when converted as an automatic module.

    OR

  • Artifact owner can add module declarations using module.info.java to their JAR. (this could result in a slow bottom-up migration)


Since the module declaration defined in the specs as:

A module declaration introduces a module name that can be used in other module declarations to express relationships between modules. A module name consists of one or more Java identifiers (§3.8) separated by "." tokens.


Intersetingly the declarations suggests -

In some cases, the Internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:

  • If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.

  • If any of the resulting package name components are keywords (§3.9), append an underscore to them.

  • If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

But keep in mind as you do so that Underscore is a keyword in Java9

int _;  // is would throw error on javac based out of JDK9
int _native; // works fine

这篇关于无法在Java 9中为自动生成的模块名称派生模块描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆