简体   繁体   English

ClassNotFoundException:org.apache.hive.jdbc.HiveDriver

[英]ClassNotFoundException: org.apache.hive.jdbc.HiveDriver

I'm pretty new to Java. 我是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 我正在尝试通过java连接到hive服务器并使用来自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 我将所有的罐子放在所需的位置并更新了pom文件,但是得到了

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. 请让我知道如何解决这个问题。

This is due to mismatch in hivesever2 version.If Hive version is more than 0.13 then You may have to use this. 这是由于hivesever2版本不匹配。如果Hive版本超过0.13,那么您可能必须使用它。

<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.. 还要确保在类路径中添加此jar。

You need to include a library in your project (JAR file) which includes that missing class org.apache.hive.jdbc.HiveDriver . 您需要在项目中包含一个库(JAR文件),其中包含缺少的类org.apache.hive.jdbc.HiveDriver Here it is a link to version 0.8.0 of it. 是它的0.8.0版链接。

From the stack trace you posted I am assuming that you are running this through IntelliJ and getting this error. 从您发布的堆栈跟踪我假设您通过IntelliJ运行此并获得此错误。

The POM describes how to build the project not how to execute the compiled project. POM描述了如何构建项目而不是如何执行已编译的项目。 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. 在你的类中,你不导入org.apache.hive.jdbc.HiveDriver所以我想IntelliJ不会确保它包含的JAR传递给类路径上的JVM。

What I believe you have to do in this case is manually pass in the location of the hive jar on the classpath. 在这种情况下,我认为你必须手动传递类路径上的hive jar的位置。 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. 在IDE的项目设置(不是POM)中的某个位置将是运行时设置,您需要包含指向hive JAR的cp-classpath命令行开关。 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. 或者你可以像David Fernadez所说的那样导入并强制IntelliJ在类路径中传递JAR的类。

I guess the reason is that the Java compiler or JVM doesn't read classpath as supposed. 我想原因是Java编译器或JVM没有按照假设读取类路径。

The environment setting is really difficult for beginners. 对于初学者来说,环境设置真的很难。 I will recommend using Cloudera quickstart VM and Java IDE to ease the pain. 我建议使用Cloudera quickstart VM和Java IDE来缓解这种痛苦。

I suffered many hours and organized it in this article: http://www.yuchao.us/2017/05/hive-jdbc-in-cloudera-hadoop.html 我在这篇文章中遇到了很多时间并组织起来: http//www.yuchao.us/2017/05/hive-jdbc-in-cloudera-hadoop.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打包并运行应用程序后,我得到java.lang.ClassNotFoundException:org.apache.hive.jdbc.HiveDriver - after packaging and running app I get java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver 错误:java.lang.ClassNotFoundException:org.apache.hive.jdbc.HiveDriver postgres外部数据包装器 - ERROR: java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver postgres Foreign data wrapper 春季无法使用Hive加载JDBC驱动程序类[org.apache.hive.jdbc.HiveDriver] - Could not load JDBC driver class [org.apache.hive.jdbc.HiveDriver] in spring with hive 如何解决 IntelliJ 上的“未找到驱动程序类 &#39;org.apache.hive.jdbc.HiveDriver&#39;”? - How to solve "Driver class 'org.apache.hive.jdbc.HiveDriver' not found" on IntelliJ? java.lang.ClassNotFoundException:Eclipse中的org.apache.hadoop.hive.jdbc.HiveDriver - java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver in eclipse Maven可部署jar“ java.lang.ClassNotFoundException:org.apache.hadoop.hive.jdbc.HiveDriver”错误 - maven deployable jar “java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver” error HiveDriver ClassNotFoundException - HiveDriver ClassNotFoundException org.apache.hive.jdbc.HiveStatement / org.apache.hadoop.hive.jdbc.HiveStatement之间的区别 - Difference between org.apache.hive.jdbc.HiveStatement / org.apache.hadoop.hive.jdbc.HiveStatement java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver - java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver “蜂巢上的火花”-原因:java.lang.ClassNotFoundException:org.apache.hive.spark.counter.SparkCounters - 'spark on hive' - Caused by: java.lang.ClassNotFoundException: org.apache.hive.spark.counter.SparkCounters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM