提交作业以激发相互冲突的jackson依赖关系?

vojdkbi0  于 2021-05-27  发布在  Spark
关注(0)|答案(2)|浏览(349)

我创建了一个使用jackson2.7.5的uberjar。我使用的是spark 1.6.2(因为我使用的是scala-2.10)。然而,每当我尝试提交我的spark作业时,我都会遇到错误,即在jackson的较新版本中的特性开关上找不到任何方法。
我假设uberjar允许我绑定自己的依赖项,即使它们与spark需要运行的东西有冲突,也可以使用某种委托类加载器来隔离冲突。不是这样吗?如果不是,我该怎么解决这个问题?
我知道有这个答案java.lang.nosuchmethoderror jackson databind和spark,它基本上建议使用sparks-jackson而不是你自己的,但是spark的jackson现在已经很老了,我有依赖于新jackson特性的代码

az31mfrm

az31mfrm1#

您需要对依赖项进行着色,以便两个版本可以共存。您的较新版本路径名将被更改以解决冲突。
如果您使用的是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

bqujaahr

bqujaahr2#

如果使用
--conf spark.driver.extraClassPath 以及 spark.executor.extraClassPath 是可能的。
请看我的回答。

相关问题