Spark开发—JAR包版本冲突问题解决

2019-03-25  本文已影响0人  西二旗老司机

问题

在spark程序中,经常需要一些外部的依赖(比如Zookeper、libthrift等),这些依赖可能本身在spark或者Hadoop客户端的jar包中就已经存在。当用户程序依赖的jar包版本和集群上spark/hadoop客户端依赖的jar包版本不一致时,可能会出现编译失败,或者执行过程中加载类失败的问题。

解决

分两种情况:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <relocations>
                <relocation>
                  <pattern>org.codehaus.plexus.util</pattern>
                  <shadedPattern>org.shaded.plexus.util</shadedPattern>
                  <excludes>
                    <exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
                    <exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
                  </excludes>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
上一篇 下一篇

猜你喜欢

热点阅读