场景
spark项目,需要在写入表后,连接impala执行invalidate。需要用到hive驱动 org.apache.hive.jdbc.HiveDriver 。
但是在引入hive-jdbc后,spark程序启动时报错,原因是spark-sql的包与hive-jdbc中的包冲突了。
解决
指定排除hive-jdbc中无用的jar包。如果你只需要hive-jdbc包,可直接排除hive-jdbc依赖的所有包:
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0-cdh5.7.1</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>但hive-shims包也被排除了。

只能根据依赖手动确认并排除依赖了。
在idea中 Maven -- Dependencies -- org.apache.hive:hive-jdbc 下可以看到hive-jdbc依赖的包。

找出认为会导致依赖冲突或非必要的包,都在pom中排除掉,如:
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0-cdh5.7.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.http*</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hive</groupId>
<artifactId>hive-serde</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hive</groupId>
<artifactId>hive-metastore</artifactId>
</exclusion>
<exclusion>
<groupId>com.codahale.metrics</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hive</groupId>
<artifactId>hive-common</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hive</groupId>
<artifactId>hive-shims</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>再次提交,运行成功。
版权声明:本文为x950913原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。