在 Apache 通用配置上调用 XMLConfiguration 的 setEntityResolver 时 Spark 提交失败

Spark submit fail on call setEntityResolver of XMLConfiguration on Apache Common Configuration

当我尝试使用 spark submit 命令提交我的申请时遇到问题:

/bin/spark-submit --class MyClass myjar.jar

我以编程方式设置了 master url。

我收到以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.configuration.XMLConfiguration.setEntityResolver(Lorg/xml/sax/EntityResolver;)V

当我 运行 我在 IDE 上的程序都可以正常工作。不会出现这个问题。

看起来您提交的 jar 可能没有它需要的所有依赖项。解决方案是构建一个 assembly jar,参见 https://maven.apache.org/plugins/maven-assembly-plugin/usage.html (for maven), or https://github.com/sbt/sbt-assembly(对于 sbt)。

终于找到问题的原因了

Spark 使用 hadoop-client-2.2.0 使用 hadoop-common 使用 common-configuration-1.6。

在我的应用程序中,我使用了 common-configuration-v1.10,其中实现了 XMLConfiguration.setEntityResolver。相反,在库的 1.6 版中,该方法不存在。

当我运行:

/bin/spark-submit --class MyClass myjar.jar

XMLConfiguration.class加载了common-configuration-v1.6,JVM没有找到方法setEntityResolver

我已经解决了在我的应用程序中使用 common-configuration-v2.0-beta1 的问题。