Java ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36212092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
提问by pam
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
我对Java很陌生。我正在尝试通过 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.
我搜索了很长一段时间的解决方案,但无法解决。请让我知道如何解决这个问题。
采纳答案by Aman
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 ..
回答by David Fernandez
回答by Kerry
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. 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.
POM 描述了如何构建项目而不是如何执行已编译的项目。在您的课程中,您没有导入,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. 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.
我相信在这种情况下您必须做的是在类路径上手动传递 hive jar 的位置。在 IDE 的项目设置(不是 POM)中的某处将是运行时设置,您需要包含将指向 hive JAR的cp
or-classpath
命令行开关。或者,您可以按照 David Fernadez 所说的去做,并导入应该强制 IntelliJ 在类路径上传递 JAR 的类。
回答by Yuchao Jiang
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