java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21262316/
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
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
提问by Krystian Szczygielski
I'm using Eclipse EE Kepler and I'm trying to run derby in my program. 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
.
Can someone help me with solving this problem?
我正在使用 Eclipse EE Kepler,并且正在尝试在我的程序中运行 derby。我添加到我的构建路径中derby.jar
,derbyclient.jar
但仍然出现以下错误:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
. 有人可以帮我解决这个问题吗?
回答by NarendraSoni
By adding jar to the build path in eclipse project, you are making derby driveravailable at compile time. 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 添加到 eclipse 项目中的构建路径,您可以在编译时使derby 驱动程序可用。但重要的是,您还应该在容器运行时使其可用。因此,将您的 jar 文件复制到服务器 lib 目录中。
回答by James Watkins
You should not add these jars to the JRE directory, nor the server's lib directory. The real solution is to bundle the jars into your war file. You should consider using a build tool such as Ant or Maven. Here's how to accomplish this using Maven:
您不应将这些 jars 添加到 JRE 目录,也不应添加到服务器的 lib 目录。真正的解决方案是将 jars 捆绑到您的 war 文件中。您应该考虑使用诸如 Ant 或 Maven 之类的构建工具。以下是使用 Maven 完成此操作的方法:
- Install Maven (for windows, following this tutorial: http://www.mkyong.com/maven/how-to-install-maven-in-windows/)
- Create a pom.xml at the root of your project.
- Add your dependencies to the pom (see http://maven.apache.org/guides/getting-started/maven-in-five-minutes.htmlfor more details)
- Add the shade plugin to your pom (see http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.htmlfor more details)
- Run "mvn package" on the project
- 安装 Maven(对于 Windows,遵循本教程:http: //www.mkyong.com/maven/how-to-install-maven-in-windows/)
- 在项目的根目录创建一个 pom.xml。
- 将您的依赖项添加到 pom(有关更多详细信息,请参阅http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html)
- 将 shade 插件添加到您的 pom(有关更多详细信息,请参阅http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html)
- 在项目上运行“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 Nenad Bulatovic
I had same problem (Windows 7, JDK 7, Eclipse Kepler) and just added C:\Program Files\Java\jdk1.7.0_25\db\lib
to the Project properties -> Run/Debug settings -> Classpath -> User entries -> Add External JARs and it works.
我遇到了同样的问题(Windows 7、JDK 7、Eclipse Kepler),刚刚添加C:\Program Files\Java\jdk1.7.0_25\db\lib
到项目属性 -> 运行/调试设置 -> 类路径 -> 用户条目 -> 添加外部 JAR 并且它可以工作。
回答by Hari Krishna
I stuck with the same problem 'java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver'. In my case, scope attribute is set to test
我遇到了同样的问题“java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver”。在我的情况下,范围属性设置为测试
<!-- 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.
您可以参考这篇文章,以获得完整的工作示例。