我尝试将GeoIP2 v2.10.0 Java API(https://github.com/maxmind/GeoIP2-java)与Apache Spark v2.2.0,Scala 2.11.8一起使用。问题是,Apache Spark在它的pom文件中有jackson-databind artifact v2.6.5,其中GeoIP2需要最小版本的jackson-databind 2.9.2。因此,我尝试使用sbt-assembly
对相关库进行着色。我在AWS-EMR上使用spark-submit
命令,但我一直收到以下依赖项错误:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.ArrayNode.<init>(Lcom/fasterxml/jackson/databind/node/JsonNodeFactory;Ljava/util/List;)V at com.maxmind.db.Decoder.decodeArray(Decoder.java:272)
上述异常的发生主要是因为jackson-databind v2.6.5是从Spark中提取而不是使用2.9.2。任何人都可以告诉我,我是否正确地进行了着色过程,或者我是否遗漏了任何东西?如何验证IntelliJ中com.fasterxml.jackson.core.*
实际上是否显示为shaded.jackson.core.*
?我尝试使用sbt-dependencyTree
插件,但只将依赖关系显示为com.fasterxml.jackson.core.*
。
以下是我的build.sbt
文件:
name := "Sessionization"
version := "0.1"
scalaVersion := "2.11.8"
assemblyShadeRules in assembly := Seq(ShadeRule.rename("com.fasterxml.jackson.core.**" -> "shaded.jackson.core.@1").inAll
//.inLibrary("com.fasterxml.jackson.core" % "jackson-databind" % "2.9.2")
//.inLibrary("com.fasterxml.jackson.core" % "jackson-core" % "2.9.2")
//.inLibrary("com.fasterxml.jackson.core" % "jackson-annotations" % "2.9.0")
//.inProject
)
// Have to use "provided" because of some deduplicate error in merging many same-name class files.
libraryDependencies ++= Seq("com.maxmind.geoip2" % "geoip2" % "2.10.0", //"org.apache.spark" %% "spark-core" % "2.2.0" % "provided",
"org.apache.spark" %% "spark-sql" % "2.2.0" % "provided"
//"org.apache.spark" %% "spark-core" % "2.2.0" excludeAll( ExclusionRule(organization="com.fasterxml.jackson.core")),
//"org.apache.spark" %% "spark-sql" % "2.2.0" excludeAll( ExclusionRule(organization="com.fasterxml.jackson.core"))
)
提前致谢!
答案 0 :(得分:0)
我说实话,我从未使用过装配阴影规则,但您尝试过以下任何一种方法:
ExclusionRule(organization = "*", name = "jackson-core")
将合并策略添加到build.sbt的底部。有点像:
assemblyMergeStrategy in assembly := {
case x if x.contains("decodeArray") => MergeStrategy.deduplicate
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
如果您仍然遇到问题,那么另一个有用的事情是将conflictManager := ConflictManager.strict
添加到您的build.sbt以识别冲突。