java.lang.NoClassDefFoundError: org/apache/hive/service/cli/thrift/TCLIService$Iface

来源:互联网 发布:多功能助手软件 编辑:程序博客网 时间:2024/06/05 19:26

今天在使用hive-jdbc连接服务器的hive时,出现了一些问题,在这里记录一下解决的方法,首先肯定要在pom中引入hive-jdbc的依赖包,然后写一段连接hive的程序,目的是获取hive中的表名和schema名称。但是运行却报错了:

java.lang.NoClassDefFoundError: org/apache/hive/service/cli/thrift/TCLIService$Ifaceat org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)at java.sql.DriverManager.getConnection(DriverManager.java:664)at java.sql.DriverManager.getConnection(DriverManager.java:208)at com.bonc.vbap.data.query.jdbc.spring.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:116)at com.bonc.vbap.data.query.jdbc.spring.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:107)at com.bonc.vbap.data.query.jdbc.spring.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:191)at com.bonc.vbap.data.query.jdbc.spring.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)at com.bonc.vbap.data.query.jdbc.ConnectionManager.getConnection(ConnectionManager.java:63)at com.bonc.vbap.data.schema.jdbc.JdbcSchemaContext$SchemaHelper.getConnection(JdbcSchemaContext.java:308)at com.bonc.vbap.data.schema.jdbc.JdbcSchemaContext$SchemaHelper.<init>(JdbcSchemaContext.java:112)at com.bonc.vbap.data.schema.jdbc.JdbcSchemaContext.getSchemaHelper(JdbcSchemaContext.java:68)at com.bonc.vbap.data.schema.jdbc.JdbcSchemaContext.getSchemaNames(JdbcSchemaContext.java:43)at com.bonc.vbap.data.service.impl.SchemaServiceImpl.getSchemaNames(SchemaServiceImpl.java:34)at com.bonc.vbap.data.schema.jdbc.TestJdbcColumn.testHiveDataQuery(TestJdbcColumn.java:252)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:52)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Caused by: java.lang.ClassNotFoundException: org.apache.hive.service.cli.thrift.TCLIService$Ifaceat java.net.URLClassLoader.findClass(URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 44 moret

提示找不到org.apache.hive.service.cli.thrift.TCLIService$Iface这个内部类,定位到..HiveDriver 105行的位置

public Connection connect(String url, Properties info) throws SQLException {    return acceptsURL(url) ? new HiveConnection(url, info) : null;  }
这里new 了一个HiveConnection的对象,这里并没有看到那个内部类的使用,然后发现在HiveConnection中有使用TCLIService.Iface接口

...TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));TOpenSessionResp openResp = client.OpenSession(new TOpenSessionReq());  if (openResp != null) {  client.CloseSession(new TCloseSessionReq(openResp.getSessionHandle()));}...
在这里抛了找不到Iface的异常,但是点进去TCLIService类中,确是存在Iface接口,所以说找不到不是因为不存在,而是有重复的类,不知道找哪个
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)")public class TCLIService {  public interface Iface {    public TOpenSessionResp OpenSession(TOpenSessionReq req) throws org.apache.thrift.TException;    public TCloseSessionResp CloseSession(TCloseSessionReq req) throws org.apache.thrift.TException;.....
所以去看下引入的依赖包,发现有hive-service和hive-service-rpc两个包中有相同的源码,所以在这里会抛异常,我就先把这其中一个依赖从hive-jdbc中去除掉,但是发现还是抛异常,我这里用的hive-jdbc1.1版本,发现hive-service是2.1版本,所以立马把两个都去除掉,重新引入一个hive-service 1.1进来就好拉,完整的pom中hive的依赖:

<dependency>  <groupId>org.apache.hive</groupId>  <artifactId>hive-jdbc</artifactId>  <exclusions>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-service-rpc</artifactId>    </exclusion>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-service</artifactId>    </exclusion>  </exclusions>  <version>1.1.0</version></dependency><dependency>  <groupId>org.apache.hive</groupId>  <artifactId>hive-service</artifactId>  <version>1.1.0</version></dependency>
其中还有一些对元数据的依赖如果没有用到也可以去除掉:

<dependency>  <groupId>org.apache.hive</groupId>  <artifactId>hive-jdbc</artifactId>  <exclusions>    <exclusion>      <groupId>joda-time</groupId>      <artifactId>joda-time</artifactId>    </exclusion>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-service-rpc</artifactId>    </exclusion>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-service</artifactId>    </exclusion>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-metastore</artifactId>    </exclusion>    <exclusion>      <groupId>org.apache.hive</groupId>      <artifactId>hive-serde</artifactId>    </exclusion>  </exclusions>  <version>1.1.0</version></dependency><dependency>  <groupId>org.apache.hive</groupId>  <artifactId>hive-service</artifactId>  <version>1.1.0</version></dependency>
OK拉。

阅读全文
0 0
原创粉丝点击