如何解决名称不符合 java 9 模块系统的 maven 依赖项? [英] How to resolve a maven dependency with a name that is not compliant with the java 9 module system?

查看:43
本文介绍了如何解决名称不符合 java 9 模块系统的 maven 依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用使用依赖项的 maven 在 java 9 中构建一个演示项目:

I am trying to build a demo project in java 9 with maven that uses the dependency:

<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-mllib_2.10</artifactId>
    <version>2.2.0</version>
</dependency>

但是,当我运行 jar 工具来确定要在我的项目的 module-info.java 中使用的自动模块名称时,我收到以下错误:

However when I run the jar tool to determine the automatic module name to use in my project's module-info.java I get the following error:

$ jar --file=spark-mllib_2.10/2.2.0/spark-mllib_2.10-2.2.0.jar --describe-module
Unable to derive module descriptor for: spark-mllib_2.10/2.2.0/spark-mllib_2.10-2.2.0.jar
spark.mllib.2.10: Invalid module name: '2' is not a Java identifier

似乎自动模块算法无法为这个 jar 提供一个有效的 java 名称.如果没有添加正确的要求,我会得到 spark mllib 中的包丢失的编译错误,例如:

It appears that the automatic module algorithm can't come up with a name that is valid java for this jar. Without adding the proper requires I get compile errors that the packages in spark mllib are missing such as:

package org.apache.spark.mllib.linalg does not exist

在添加官方保留模块名称或自己的模块信息之前,我是否可以在我的项目中使用此依赖项?

Is there anyway I can use this dependency in my project before it adds an official reserved module name or its own module-info?

推荐答案

为了获得适当的长期解决方案,Apache Spark 项目必须将模块声明 (module.info.java) 添加到它们的JAR 或在其 JAR 的清单中设置 Automatic-Module-Name 条目.

For a proper, long-term solution the Apache Spark project must either add module declarations (module.info.java) to their JARs or set the Automatic-Module-Name entry in their JAR's manifest.

如果你等不及,你可以很容易地自己完成后者:

If you can't wait for that, you can do the latter yourself quite easily:

  1. 创建一个文件manifest.txt,内容如下:

Automatic-Module-Name: org.apache.spark.mlib2

  • 将该条目附加到 JAR 的清单中:

  • Append that entry to the JAR's manifest:

    jar --update --file spark-mllib_2.10.jar --manifest=manifest.txt
    

  • 确保它有效:

  • Make sure it worked:

    jar --describe-module --file spark-mllib_2.10.jar
    

  • 如果您打算在实际项目中使用此 JAR,您可以将其提供给您的同事,我会为此创建一个新版本(可能是 2.10.patched-auto-name?),将其上传到公司的 Nexus,然后编辑 POM 以将原始依赖项替换为该依赖项.

    If you're planning to use this JAR in a real project, you would make it available to your colleagues, for which I would create a new version (maybe 2.10.patched-auto-name?), upload it to the company's Nexus and then edit the POMs to replace the original dependency with that one.

    总而言之,这可能不值得付出努力,您可能只想等待.

    All in all, this is likely not worth the effort and you just might want to wait.

    这篇关于如何解决名称不符合 java 9 模块系统的 maven 依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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