ClassNotFoundException: org.apache.hive.jdbc.HiveDriver

I am new to Java. I am trying to connect to a hive server through java and use the 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 put all the jars in the right place 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 a while, but could not solve it. Please let me know how to fix this.

+5
source share
4 answers

This is due to a mismatch in the version of hivesever2. If the Hive version is greater than 0.13, you may need 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 to your class path.

+9
source

You need to include the library in your project (JAR file), which includes the missing org.apache.hive.jdbc.HiveDriver class. Here is a link to version 0.8.0.

+2
source

From the stack trace you posted, I assume that you run this through IntelliJ and get this error.

POM describes how to create a project, not how to execute a compiled project. In your class, you are not importing org.apache.hive.jdbc.HiveDriver , so I assume that IntelliJ is not going to guarantee that its containing JAR is passed to the JVM in the classpath.

What I think you need to do in this case is to manually pass the location of the bush bush on the way to the classes. Somewhere in the project settings (NOT POM) in your IDE, where there will be runtime settings, you will need to turn on the cp command line switch or -classpath , which will point to the JAR hive. Or, alternatively, you can do as David Fernades says and import a class, which should force IntelliJ to pass the JAR to the classpath.

+2
source

I think the reason is that the Java or JVM compiler does not read the classpath as intended.

Setting up an environment for beginners is really complicated. I recommend using the Cloudera VM and Java IDE keyboard shortcuts to relieve pain.

I visited for many hours and organized it in this article: http://www.yuchao.us/2017/05/hive-jdbc-in-cloudera-hadoop.html

0
source

Source: https://habr.com/ru/post/1245738/


All Articles