Hive ClassNotFoundException even though all jars were added in maven repository
<p>I added all the jars which are required for this project,but i am unable to resolve this exception.can anyone give e suggestion regarding this.
Can u also please tell tell how to give hive database access permissions.
Thanks in advance. </p>

<pre><code>java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at org.ezytruk.com.CreateHiveExternalTable.createHiveExternalTable(CreateHiveExternalTable.java:20)
    at org.ezytruk.com.CreateHiveExternalTable.main(CreateHiveExternalTable.java:53)
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:hive://localhost/EZYTRUK
    at java.sql.DriverManager.getConnection(DriverManager.java:596)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at org.ezytruk.com.CreateHiveExternalTable.createHiveExternalTable(CreateHiveExternalTable.java:39)
    at org.ezytruk.com.CreateHiveExternalTable.main(CreateHiveExternalTable.java:53)
</code></pre>

<p>pom.xml</p>

<pre><code>&lt;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"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;BigData&lt;/groupId&gt;
  &lt;artifactId&gt;BigData&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;properties&gt;
  &lt;slf4j.version&gt;1.6.1&lt;/slf4j.version&gt;
  &lt;hadoop-version&gt;2.6.0&lt;/hadoop-version&gt;
  &lt;mysql-connector-version&gt;5.1.40&lt;/mysql-connector-version&gt;
  &lt;sqoop-core-version&gt;1.99.3&lt;/sqoop-core-version&gt;
  &lt;zookeeper-version&gt;3.4.9&lt;/zookeeper-version&gt;
  &lt;hive-jdbc-version&gt;1.2.1&lt;/hive-jdbc-version&gt;
  &lt;commons-io-version&gt;2.2&lt;/commons-io-version&gt;
  &lt;commons-logging.version&gt;1.2&lt;/commons-logging.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;commons-io&lt;/groupId&gt;
    &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
    &lt;version&gt;${commons-io-version}&lt;/version&gt;
&lt;/dependency&gt;
 &lt;dependency&gt;
        &lt;groupId&gt;commons-logging&lt;/groupId&gt;
        &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
        &lt;version&gt;${commons-logging.version}&lt;/version&gt;
   &lt;/dependency&gt;        
   &lt;dependency&gt;
    &lt;groupId&gt;mysql&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
    &lt;version&gt;${mysql-connector-version}&lt;/version&gt;
   &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-common&lt;/artifactId&gt;
    &lt;version&gt;${hadoop-version}&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-client&lt;/artifactId&gt;
    &lt;version&gt;${hadoop-version}&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-hdfs&lt;/artifactId&gt;
    &lt;version&gt;${hadoop-version}&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-mapreduce-client-core&lt;/artifactId&gt;
    &lt;version&gt;${hadoop-version}&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-yarn-common&lt;/artifactId&gt;
    &lt;version&gt;${hadoop-version}&lt;/version&gt;
&lt;/dependency&gt;
 &lt;dependency&gt;
    &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
    &lt;artifactId&gt;hadoop-core&lt;/artifactId&gt;
    &lt;version&gt;1.2.1&lt;/version&gt;
&lt;/dependency&gt;
 &lt;dependency&gt; 
    &lt;groupId&gt;org.apache.sqoop&lt;/groupId&gt;
    &lt;artifactId&gt;sqoop-core&lt;/artifactId&gt;
    &lt;version&gt;${sqoop-core-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.sqoop&lt;/groupId&gt;
    &lt;artifactId&gt;sqoop-client&lt;/artifactId&gt;
    &lt;version&gt;${sqoop-core-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.sqoop&lt;/groupId&gt;
    &lt;artifactId&gt;sqoop-common&lt;/artifactId&gt;
    &lt;version&gt;${sqoop-core-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.sqoop.connector&lt;/groupId&gt;
    &lt;artifactId&gt;sqoop-connector-generic-jdbc&lt;/artifactId&gt;
    &lt;version&gt;${sqoop-core-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.sqoop&lt;/groupId&gt;
    &lt;artifactId&gt;sqoop&lt;/artifactId&gt;
    &lt;version&gt;1.4.1-incubating&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.zookeeper&lt;/groupId&gt;
    &lt;artifactId&gt;zookeeper&lt;/artifactId&gt;
    &lt;version&gt;${zookeeper-version}&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-jdbc&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-exec&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-metastore&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-common&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-service&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-shims&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
    &lt;artifactId&gt;hive-serde&lt;/artifactId&gt;
    &lt;version&gt;${hive-jdbc-version}&lt;/version&gt;
&lt;/dependency&gt;

&lt;/dependencies&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;build&gt;
    &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.3&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.7&lt;/source&gt;
          &lt;target&gt;1.7&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.6&lt;/version&gt;
        &lt;configuration&gt;
          &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</code></pre>

<p>Program:</p>

<pre><code> package org.hive.com;

    import java.io.FileNotFoundException;
    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.fs.Path;

    import com.mysql.jdbc.Statement;

    public class CreateHiveExternalTable {

        public static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

        public static void createHiveExternalTable() throws FileNotFoundException, IOException, SQLException {
            try {
                Class.forName(driverName);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            Configuration config = new Configuration();
            config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/core-site.xml"));
            config.addResource(new Path("/usr/local/hadoop/etc/hadoop/conf/hdfs-site.xml"));



        Connection connect = DriverManager.getConnection("jdbc:hive://localhost/hivedb","hive","");
            Statement stmt = (Statement) connect.createStatement();
            //String tableName = properties.getProperty("hive_table_name");
            stmt.executeQuery("CREATE EXTERNAL TABLE IF NOT EXISTS"
             +"SHIPPER(S_ID INT,S_NAME VARCHAR(100),S_ADDR VARCHAR(100),S_CITY VARCHAR(100)"
             +"ROW FORMAT DELIMITED FIELDS TERMINATED BY ','"
             +"LOCATION 'hdfs://localhost://hive'");

            System.out.println("Table created.");
            connect.close();
        }

         public static void main(String[] args) throws FileNotFoundException, IOException, SQLException{
             CreateHiveExternalTable hiveTable = new CreateHiveExternalTable();
             hiveTable.createHiveExternalTable();
         }     

        }    
</code></pre>