问题
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>
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
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?
回答1:
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:
create a file
manifest.txt
with the following content:Automatic-Module-Name: org.apache.spark.mlib2
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
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.
来源:https://stackoverflow.com/questions/46683561/how-to-resolve-a-maven-dependency-with-a-name-that-is-not-compliant-with-the-jav