提交工作以激发与杰克逊相关的冲突?

时间:2016-10-26 01:03:31

标签: json scala apache-spark jackson

我创建了一个使用jackson 2.7.5的超级jar。我使用spark 1.6.2(因为我在scala-2.10上)。但是,每当我尝试提交我的spark作业时,我都会收到有关在后来的jackson版本中的功能开关上找不到任何方法的错误。

我会假设一个超级jar允许我捆绑我自己的依赖项,即使它们与使用某种委托类加载器来隔离冲突时需要运行的spark冲突。这不是这种情况吗?如果不是,我该如何解决这个问题呢?

我知道有这个答案java.lang.NoSuchMethodError Jackson databind and Spark基本上建议使用sparks jackson而不是你自己的,但是spark的杰克逊现在已经很老了,而且我的代码依赖于新的功能杰克逊

2 个答案:

答案 0 :(得分:1)

您需要遮盖依赖性,以便两个版本可以共存。您的较新版本路径名称将被更改以解决冲突。

如果您使用的是Maven:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <groupId><!-- YOUR_GROUP_ID --></groupId>
  <artifactId><!-- YOUR_ARTIFACT_ID --></artifactId>
  <version><!-- YOUR_PACKAGE_VERSION --></version>

  <dependencies>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_2.11</artifactId>
      <version><!-- YOUR_SPARK_VERSION --></version>
      <scope>provided</scope>
    </dependency>
    <!-- YOUR_DEPENDENCIES -->
  </dependencies>
  <build>
    <plugins>

      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion><!-- YOUR_SCALA_VERSION --></scalaVersion>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass><!-- YOUR_APPLICATION_MAIN_CLASS --></mainClass>
                </transformer>
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/maven/**</exclude>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
              <relocations>
                <relocation>
                  <pattern>com</pattern>
                  <shadedPattern>repackaged.com.google.common</shadedPattern>
                  <includes>
                    <include>com.google.common.**</include>
                  </includes>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>

来源:https://cloud.google.com/dataproc/docs/guides/manage-spark-dependencies

答案 1 :(得分:1)

如果使用--conf spark.driver.extraClassPathspark.executor.extraClassPath是可行的。

请查看我的回复here