如何添加"requires"对于名称中带有“-"(连字符)的伪像 [英] How to add "requires" for artifact having "-"(hyphen) in its name

查看:118
本文介绍了如何添加"requires"对于名称中带有“-"(连字符)的伪像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Maven pom.xml中包含了这些依赖项:

I've included these dependencies in my Maven pom.xml:

 <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpclient.version}</version>
</dependency>

<dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
</dependency>

我试图像这样在module-info.java中添加此依赖项:

I am trying to add this dependency in module-info.java like so:

module io.github.wildcraft.restclient {
    requires httpcore; // no compilation problem
    requires httpclient; // no compilation problem
    requires commons-io; // shows compilation error
}

对于commons-io,我收到一个编译错误.我该如何进行这项工作?

For commons-io, I receive a compilation error. How can I make this work?

推荐答案

简短版

使用requires commons.io. (通常,请参见空指针的答案如何学习模块的名称.)

Short Version

Use requires commons.io. (In general, see nullpointer's answer how to learn a module's name.)

由于commons-io.jar尚未模块化,因此您正在创建一个自动模块,该模块的模块系统必须为此起一个名字. ModuleFinder 的Javadoc描述了这种情况:

Since commons-io.jar is not yet modularized, you are creating an automatic module, for which the module system has to come up with a name. The Javadoc of ModuleFinder describes how that happens:

此方法返回的模块查找器支持打包为JAR文件的模块. [...]在其顶级目录中没有module-info.class的JAR文件定义了一个自动模块,如下所示:

The module finder returned by this method supports modules packaged as JAR files. [...] A JAR file that does not have a module-info.class in its top-level directory defines an automatic module, as follows:

  • 如果JAR文件的主要清单中具有属性"Automatic-Module-Name",则其值为模块名称.否则,模块名称是从JAR文件的名称派生的.

  • If the JAR file has the attribute "Automatic-Module-Name" in its main manifest then its value is the module name. The module name is otherwise derived from the name of the JAR file.

版本和模块名称[...]源自JAR文件的文件名,如下所示:

The version and the module name [...] are derived from the file name of the JAR file as follows:

  • [...]

  • [...]

模块名称中的所有非字母数字字符([^ A-Za-z0-9])都用点(.")替换,所有重复的点都用一个点替换,并且所有前导并删除尾随点.

All non-alphanumeric characters ([^A-Za-z0-9]) in the module name are replaced with a dot ("."), all repeating dots are replaced with one dot, and all leading and trailing dots are removed.

最后两个项目符号适用于未针对Java 9准备的自动模块,例如到commons.io.来自同一Javadoc的以下示例说明了您的情况:

The last two bullets apply to automatic modules that are not prepared for Java 9, e.g. to commons.io. This example from the same Javadoc explains what happens in your case:

  • 作为示例,名为"foo-bar.jar"的JAR文件将派生模块名称"foo.bar",而没有版本.名为"foo-bar-1.2.3-SNAPSHOT.jar"的JAR文件将派生模块名称"foo.bar"和"1.2.3-SNAPSHOT"作为版本.
  • As an example, a JAR file named "foo-bar.jar" will derive a module name "foo.bar" and no version. A JAR file named "foo-bar-1.2.3-SNAPSHOT.jar" will derive a module name "foo.bar" and "1.2.3-SNAPSHOT" as the version.

因此requires commons.io应该可以工作.

这篇关于如何添加"requires"对于名称中带有“-"(连字符)的伪像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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