gpt4 book ai didi

java - 打包并运行应用程序后,我得到java.lang.ClassNotFoundException:org.apache.hive.jdbc.HiveDriver

转载 作者:行者123 更新时间:2023-12-02 20:52:42 25 4
gpt4 key购买 nike

当我尝试在IDEA中运行代码时,没有出现此错误,但是在打包并尝试使用

java -cp app.jar com.hive.connect.controller.RecordController

我得到这个异常(exception)。
java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver

我的行家
  <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>

我的密码
public class RecordController {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";

public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName(driverName);
Connection con = DriverManager
.getConnection("jdbc:hive2://host:port/db;" +
"principal=principal");
Statement stmt = con.createStatement();
String tableName = "evkuzmin_testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
}
}

为什么会这样?

编辑
完全错误
Exception in thread "main" java.lang.ClassNotFoundException: org.apache.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 com.hive.connect.controller.RecordController.main(RecordController.java:18)

最佳答案

尝试这样:

"%JAVA_HOME%\bin\java.exe" -cp  "%~dp0\hive-jdbc.jar;%~dp0\app.jar" com.hive.connect.controller.RecordController

代替这个:
java -cp app.jar com.hive.connect.controller.RecordController

该错误是由于尝试运行Java代码时Hive JDBC jar不可用(而这又会尝试加载Hive JDBC jar)。

希望这可以帮助!

关于java - 打包并运行应用程序后,我得到java.lang.ClassNotFoundException:org.apache.hive.jdbc.HiveDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45564332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com