如何使用与Java 9模块系统不兼容的名称来解析Maven依赖关系? [英] How to resolve a maven dependency with a name that is not compliant with the java 9 module system?

查看:150
本文介绍了如何使用与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

看来,自动模块算法无法为该罐子提供有效的Java名称.如果不添加适当的要求,我会收到火花错误的mlmllib软件包丢失的编译错误,例如:

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项目必须在其JAR中添加模块声明(module.info.java)或在其中设置Automatic-Module-Name条目他们的JAR清单.

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天全站免登陆