“找不到类:无法加载 JDBC 驱动程序 org.apache.derby.jdbc.EmbeddedDriver"尽管在类路径中包含了必需的 JAR [英] "Class Not Found: JDBC driver org.apache.derby.jdbc.EmbeddedDriver could not be loaded" despite having included required JARs in classpath

查看:32
本文介绍了“找不到类:无法加载 JDBC 驱动程序 org.apache.derby.jdbc.EmbeddedDriver"尽管在类路径中包含了必需的 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在遵循本教程的同时,为了测试如果一切都设置正确,我会从 Eclipse 运行设置"Ant 目标.以下是我收到的错误消息:

 构建文件:C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml设置:掉落表:[echo] C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\classes;C:\Users\bingis_khan\Downloads\db-derby-10.15.2.0-bin\db-derby-10.15.2.0-bin\lib\derby.jar;C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\lib\JDBCTutorial.jar;C:\apache\xalan-j_2_7_2\xalan.jar构建失败C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml:141:执行此行时出现以下错误:C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml:84: Class Not Found: JDBC driver org.apache.derby.jdbc.EmbeddedDriver 无法加载总时间:374 毫秒

这里的 [echo] 设置为打印 CLASSPATH.正如下一节所示,类路径中的路径与这些档案的实际位置相匹配:

C:\Users\bingis_khan\Downloads\db-derby-10.15.2.0-bin\db-derby-10.15.2.0-bin\lib目录04/20/2021 08:57 PM <DIR>.04/20/2021 08:57 PM <DIR>..04/20/2021 08:57 PM 3,683,035 derby.jar04/20/2021 08:57 PM 1,490 derby.war04/20/2021 08:57 PM 601,103 derbyclient.jar04/20/2021 08:57 PM 83,942 derbyLocale_cs.jar04/20/2021 08:57 PM 99,882 derbyLocale_de_DE.jar*剪*

我尝试过的:

  • 尝试将反斜杠更改为斜杠,反之亦然.
  • 尝试将 derby.jar 更改为 derbyclient.jar.
  • 以防万一将存档(在 Ant 之外)导入到 Eclipse 项目中.上述方法均无效(甚至更改了setup"的输出).

我看过的地方:

  • 此处 - 海报未将 derby.jar 添加到类路径.
  • 也在这里 - 不同的情况,但仍然应用了解决方案 - 没有.
  • 其他一些,但大多数是指运行时 ClassNotFoundException.我什至还没有走那么远......

还附上相关的 Ant 目标:

<echo>${toString:CLASSPATH}</echo><sql driver="${DB.DRIVER}";url="${DB.URL}";userid="${DB.USER}";密码=${DB.PASSWORD}";类路径引用=类路径";delimiter="${DB.DELIMITER}";自动提交=假"onerror=继续"><transaction src=./sql/${DB.VENDOR}/drop-tables.sql"></transaction></目标>

解决方案

由于您使用的是 Derby 10.15,因此您还必须在嵌入式驱动程序的类路径中包含 derbyshared.jar.>

更多信息:http://db.apache.org/derby/releases/release-10.15.1.3.cgi#Release%20Notes%20for%20Apache%20Derby%2010.15.1.3

特别注意这部分:

<块引用>

添加了一个新的 jar 文件 (derbyshared.jar).所有德比配置都需要它.此外,现在运行网络服务器、使用 Derby 数据源以及直接引用 JDBC 驱动程序时都需要 derbytools.jar 库.

While following this tutorial, in order to test if everything is set up correctly, I ran the 'setup' Ant target from Eclipse. The following is the error message I got:

    Buildfile: C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml
setup:
drop-tables:
     [echo] C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\classes;C:\Users\bingis_khan\Downloads\db-derby-10.15.2.0-bin\db-derby-10.15.2.0-bin\lib\derby.jar;C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\lib\JDBCTutorial.jar;C:\apache\xalan-j_2_7_2\xalan.jar

BUILD FAILED
C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml:141: The following error occurred while executing this line:
C:\Users\bingis_khan\eclipse-workspace\JDBCTutorial\build.xml:84: Class Not Found: JDBC driver org.apache.derby.jdbc.EmbeddedDriver could not be loaded

Total time: 374 milliseconds

This [echo] here is set up to print the CLASSPATH. As the next section shows, the path(s) in classpath match the actual locations of these archives:

Directory of C:\Users\bingis_khan\Downloads\db-derby-10.15.2.0-bin\db-derby-10.15.2.0-bin\lib

04/20/2021  08:57 PM    <DIR>          .
04/20/2021  08:57 PM    <DIR>          ..
04/20/2021  08:57 PM         3,683,035 derby.jar
04/20/2021  08:57 PM             1,490 derby.war
04/20/2021  08:57 PM           601,103 derbyclient.jar
04/20/2021  08:57 PM            83,942 derbyLocale_cs.jar
04/20/2021  08:57 PM            99,882 derbyLocale_de_DE.jar
*snip*

What I've tried:

  • Experimented with changing backslashes to slashes and vice-versa.
  • Tried changing derby.jar to derbyclient.jar.
  • Just in case imported the archive (outside of Ant) to the Eclipse project. None of the above methods worked (or even changed the output of "setup").

Where I've looked:

  • here - Poster did not add derby.jar to classpath.
  • also here - Different circumstances, but still applied the solution - nothing.
  • Some others, but most referred to runtime ClassNotFoundException. I haven't even gotten that far...

EDIT: Also attaching the relevant Ant target:

<target name="drop-tables">
    <echo>${toString:CLASSPATH}</echo>
    <sql driver="${DB.DRIVER}" url="${DB.URL}" userid="${DB.USER}"
         password="${DB.PASSWORD}" classpathref="CLASSPATH"
         delimiter="${DB.DELIMITER}" autocommit="false" onerror="continue">
      <transaction src="./sql/${DB.VENDOR}/drop-tables.sql"></transaction>
    </sql>
  </target>

解决方案

Since you're using Derby 10.15, you have to also have derbyshared.jar in your classpath for the embedded driver.

More information here: http://db.apache.org/derby/releases/release-10.15.1.3.cgi#Release%20Notes%20for%20Apache%20Derby%2010.15.1.3

In particular, note this part:

A new jar file (derbyshared.jar) has been added. All Derby configurations require it. In addition, the derbytools.jar library is now required when running the network server, when using Derby DataSources, and when directly referencing the JDBC drivers.

这篇关于“找不到类:无法加载 JDBC 驱动程序 org.apache.derby.jdbc.EmbeddedDriver"尽管在类路径中包含了必需的 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆