ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
Solution 1
This is due to mismatch in hivesever2 version.If Hive version is more than 0.13 then You may have to use this.
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
Also make sure you add this jar in you class path..
Solution 2
From the stack trace you posted I am assuming that you are running this through IntelliJ and getting this error.
The POM describes how to build the project not how to execute the compiled project. In your class you do not import org.apache.hive.jdbc.HiveDriver
so I imagine that IntelliJ is not going to ensure that its containing JAR is passed to the JVM on the classpath.
What I believe you have to do in this case is manually pass in the location of the hive jar on the classpath. Somewhere in the project settings (NOT the POM) in your IDE where will be runtime settings, you will need to include the cp
or -classpath
commandline switch which will point to the hive JAR. Or alternatively you can do as David Fernadez says and import the class which should force IntelliJ to pass the JAR in on the classpath.
Solution 3
You need to include a library in your project (JAR file) which includes that missing class org.apache.hive.jdbc.HiveDriver
. Here it is a link to version 0.8.0 of it.
Solution 4
I guess the reason is that the Java compiler or JVM doesn't read classpath as supposed.
The environment setting is really difficult for beginners. I will recommend using Cloudera quickstart VM and Java IDE to ease the pain.
I suffered many hours and organized it in this article: http://www.yuchao.us/2017/05/hive-jdbc-in-cloudera-hadoop.html
Comments
-
pam about 4 years
I'm pretty new to Java. I'm trying to connect to hive server through java and used sample code from https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC
import java.sql.SQLException; public class HiveJdbcClient { //private static String driverName = "org.apache.hive.jdbc.HiveDriver"; public static void main(String[] args) throws SQLException { try { Class.forName("org.apache.hive.jdbc.HiveDriver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(1); } } }
I placed all the jars in the required location and updated the pom file, but getting
java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver at 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) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at HiveJdbcClient.main(HiveJdbcClient.java:7) 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:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
I searched for a solution for quite some time, but couldn't solve it. Please let me know how to fix this.
-
pam over 8 yearsI have hive-jdbc-0.9.0 in place.
-
David Fernandez over 8 yearsare you using eclipse? have you made sure the
jar
is on your classpath? how are you including it in your project? Try creating a line in your file likeHiveDriver h;
and try to import it and compile so you'll check if you have it correctly attached. -
pam over 8 yearsThank you. I was away for quite some time. I tried all the three responses and Aman's solution fixed the issue. @David
-
curtisp over 7 yearsWhere does this go? Assuming it is config file. What is name of file.
-
DharaPPatel over 7 yearscan you please mention where to apply this change ? I am facing same issues
-
Suresh over 6 yearsadd above decency to your pom.xml