简体   繁体   English

java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver

[英]java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver

I'm using Eclipse EE Kepler and I'm trying to run derby in my program. 我正在使用Eclipse EE Kepler,而我正试图在我的程序中运行derby。 I added to my build path derby.jar and derbyclient.jar and still I'm getting the following error: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver . 我添加到我的构建路径derby.jarderbyclient.jar ,但我仍然收到以下错误: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver Can someone help me with solving this problem? 有人可以帮我解决这个问题吗?

I stuck with the same problem 'java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver'. 我遇到了同样的问题'java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver'。 In my case, scope attribute is set to test 在我的例子中,scope属性设置为test

    <!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.13.1.1</version>
        <scope>test</scope>
    </dependency>

You need to remove the scope element from the dependency and update the dependency like below. 您需要从依赖项中删除scope元素并更新依赖项,如下所示。

    <!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.13.1.1</version>
    </dependency>

You may refer this post , to get complete working example. 您可以参考这篇文章 ,以获得完整的工作示例。

You should not add these jars to the JRE directory, nor the server's lib directory. 您不应将这些jar添加到JRE目录,也不应添加到服务器的lib目录。 The real solution is to bundle the jars into your war file. 真正的解决方案是将罐子捆绑到war文件中。 You should consider using a build tool such as Ant or Maven. 您应该考虑使用Ant或Maven等构建工具。 Here's how to accomplish this using Maven: 以下是使用Maven实现此目的的方法:

  1. Install Maven (for windows, following this tutorial: http://www.mkyong.com/maven/how-to-install-maven-in-windows/ ) 安装Maven(适用于Windows,遵循本教程: http//www.mkyong.com/maven/how-to-install-maven-in-windows/
  2. Create a pom.xml at the root of your project. 在项目的根目录下创建一个pom.xml。
  3. Add your dependencies to the pom (see http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html for more details) 将您的依赖项添加到pom(有关详细信息,请参阅http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
  4. Add the shade plugin to your pom (see http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html for more details) 将阴影插件添加到您的pom中(有关详细信息,请参阅http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
  5. Run "mvn package" on the project 在项目上运行“mvn package”

Here is a sample pom.xml ( this is probably not a functional example ): 这是一个示例pom.xml( 这可能不是一个功能示例 ):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.10.2.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                          <goal>shade</goal>
                        </goals>
                        <configuration>
                          <minimizeJar>true</minimizeJar>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

By adding jar to the build path in eclipse project, you are making derby driver available at compile time. 通过在eclipse项目中将jar添加到构建路径,您可以在编译时使用derby驱动程序 But it is important that you should also make it available when container is running it. 但重要的是,当容器运行时,您也应该使它可用。 So copy your jar file in server lib directory. 因此, 将jar文件复制到服务器lib目录中。

我有同样的问题(Windows 7,JDK 7,Eclipse Kepler),只是将C:\\Program Files\\Java\\jdk1.7.0_25\\db\\lib到项目属性 - >运行/调试设置 - >类路径 - >用户条目 - >添加外部JAR,它可以工作。

暂无
暂无

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

相关问题 Apache Derby 10.15.* - java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver - Apache Derby 10.15.* - java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver 尝试将JPA与Derby一起使用时ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver - ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver when trying to use JPA with Derby Derby 在使用 Maven 时给出 ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver - Derby gives ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver while using Maven 尝试设置Java DB:“未找到类:无法加载JDBC驱动程序org.apache.derby.jdbc.EmbeddedDriver” - Trying to set up Java DB: “Class Not Found: JDBC driver org.apache.derby.jdbc.EmbeddedDriver could not be loaded” 配置错误。 连接到数据库时找不到类 [org.apache.derby.jdbc.EmbeddedDriver] - Configuration error. Class [org.apache.derby.jdbc.EmbeddedDriver] not found while connecting to DB java.lang.ClassNotFoundException:org.apach.derby.jdbc.ClientDriver - java.lang.ClassNotFoundException: org.apach.derby.jdbc.ClientDriver 日志中的Heroku错误:java.lang.ClassNotFoundException:org.apache.derby.jdbc.ClientDriver - Heroku error in logs: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver 创建数据库时出错:java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver - An error occurred while creating the database: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver 线程“主”java.lang.ClassNotFoundException 中的异常:org.apache.derby.jdbc.ClientDriver - Exception in thread “main” java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver “找不到类:JDBC 驱动程序 org.apache.derby.jdbc.EmbeddedDriver 无法加载”尽管已在类路径中包含所需的 JARs - "Class Not Found: JDBC driver org.apache.derby.jdbc.EmbeddedDriver could not be loaded" despite having included required JARs in classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM