title: Exception while connecting to Hive using JDBC and Kerberos authentication
body: <p>I am trying to connect to Hive using JDBC and Kerberos authentication in Java.
  To do that, I came up with the following code.</p>
  
  <pre><code>import java.io.IOException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.security.UserGroupInformation;
  
  public class DbManager {
  private static Connection hiveConnection;
  // get Hive Connection
  public static Connection qwtHiveConnection() throws IOException, SQLException {
  
      System.out.println("Preparing Hive connection1");
      Configuration conf = new Configuration();
      conf.set("hadoop.security.authentication", "Kerberos");
      UserGroupInformation.setConfiguration(conf);
      UserGroupInformation.loginUserFromKeytab("username@HLC.ABC.QW.COM", "path of keytab");
      // Hive Connection
      try {
          Class.forName("org.apache.hive.jdbc.HiveDriver");
          if(hiveConnection == null) {
              hiveConnection = DriverManager.getConnection("jdbc:hive2://abcd1dq000.hlc.abc.qw.com:10000/finance;principal=hive/_HOST@HLC.ABC.QW.COM", "usrname", "pwd");
              return hiveConnection;
          } else {
          return hiveConnection;
          }
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
          return null;
      } catch (SQLException e) {
          e.printStackTrace();
          return null;
      }
  }
  }
  </code></pre>
  
  <p>The Hadoop version I see from the command 'hadoop version':
      Hadoop 2.7.3.2.6.2.0-205
      This command was run using /usr/hdp/2.6.2.0-205/hadoop/hadoop-common-2.7.3.2.6.2.0-205.jar</p>
  
  <p>I am using the following jar files in the project:</p>
  
  <pre><code>hive-jdbc-2.2.0.jar,
  postgresql-9.4.1212.jar,
  apache-commons.jar,
  slf4j-api-1.7.25.jar,
  hadoop-commons-2.6.2.jar,
  guava-18.0.jar,
  commons-configuration-1.9.jar,
  commons-lang-2.6.jar,
  hadoop-auth-2.6.2.jar,
  hadoop-core-1.2.0.jar
  </code></pre>
  
  <p>When I run the jar, I get the exception:</p>
  
  <pre><code>Preparing Hive connection1
  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  Kerberos Connected
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hive/service/rpc/thrift/TCLIService$Iface
      at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
      at java.sql.DriverManager.getConnection(DriverManager.java:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:247)
      at com.dbconnections.gphive.DbManager.getHiveConnection(DbManager.java:35)
      at com.recordcount.dao.GpHiveRecords.getHiveTableCount(GpHiveRecords.java:93)
      at com.recordcount.entry.StartCount.main(StartCount.java:13)
  Caused by: java.lang.ClassNotFoundException: org.apache.hive.service.rpc.thrift.TCLIService$Iface
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 6 more
  </code></pre>