Eclipse 无法找到 org.sqlite.JDBC (Java)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6870254/
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
Eclipse not able to find org.sqlite.JDBC (Java)
提问by Abstract_rated
I'm new to Eclipse. I'm trying to connect to SQLLite database. I'm following examaple from http://www.zentus.com/sqlitejdbc/usage.html. I downloaded the jar file, imported into the project but once I run the code I get following exception
我是 Eclipse 的新手。我正在尝试连接到 SQLLite 数据库。我正在关注http://www.zentus.com/sqlitejdbc/usage.html 中的示例。我下载了 jar 文件,导入到项目中,但是一旦我运行代码,就会出现以下异常
Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.amazon.IP2Zip.Test.main(Test.java:7)
Seems like it is not able to find the class, even though I imported the jar file into the project.
似乎无法找到类,即使我将 jar 文件导入到项目中。
Any help would be greatly appreciated :)
任何帮助将不胜感激 :)
回答by Shamis Shukoor
right click on the project and select properties from that select build path and there in the libraries section select add external Jar's and browse to the location where the jar file is stored.
右键单击项目并从选择的构建路径中选择属性,然后在库部分选择添加外部 Jar 并浏览到存储 jar 文件的位置。
Hope this will do the trick
希望这能解决问题
回答by Sandeep Pathak
According to the java.lang.ClassNotFoundException,classes cannot be found in the CLASSPATH. Try to put that path into build path by doing something like this :-
根据java.lang.ClassNotFoundException,在 CLASSPATH 中找不到类。尝试通过执行以下操作将该路径放入构建路径中:-
Project->BuildPath->libraries ->Add External jars.
项目->BuildPath->libraries->Add External jars。
回答by Apok
This may not be true for your case, but I just resolved a similar problem that appeared to defy logic. There are a few similar questions on this topic, but all came up short in solving my problem. I figured I'd might as well mention the problem I encountered.
这可能不适用于您的情况,但我刚刚解决了一个似乎违反逻辑的类似问题。关于这个主题有一些类似的问题,但都未能解决我的问题。我想我不妨提一下我遇到的问题。
I downloaded the JAR, which I obtained via a quick search. I first tried to include this library via Eclipse, which I'm quite familiar with. I added the JAR to the build path as usual, and proceeded to run my program expecting some silly output that would confirm that org.sqlite.JDBC
had been found. Unfortunately, I was instead met with the ClassNotFoundException.
我下载了通过快速搜索获得的 JAR。我首先尝试通过我非常熟悉的 Eclipse 包含这个库。我像往常一样将 JAR 添加到构建路径中,然后继续运行我的程序,期待一些愚蠢的输出来确认org.sqlite.JDBC
已找到。不幸的是,我遇到了 ClassNotFoundException。
I looked at the contents of the JAR, and sure enough, org.sqlite.JDBC
appeared to be there. After that point, I figured I must have done something wrong, and searched up a bunch of similar questions to determine where I went wrong. The only problem was, the majority of them were recommending exactly what I did to begin with! I then considered that perhaps something was funky with my Eclipse setup, so I ran it (specifying the classpath) manually via the command line. Even so, I was met with a ClassNotFoundException
.
我查看了 JAR 的内容,果然,org.sqlite.JDBC
似乎在那里。在那之后,我想我一定做错了什么,并搜索了一堆类似的问题来确定我哪里出错了。唯一的问题是,他们中的大多数人都在推荐我一开始所做的!然后我认为我的 Eclipse 设置可能有些奇怪,所以我通过命令行手动运行它(指定类路径)。尽管如此,我还是遇到了一个ClassNotFoundException
.
At the end of my rope, I then considered the possibility of what I had thought was extremely unlikely--that the JAR was somehow corrupted--and this time went directly to the project download page for a fresh copy. On adding the JAR to the build path in Eclipse, I noted that it had a slightly different structure than the one I had previously. Then I attempted to run it and... it worked! So in the extreme unlikelihood that you download a corrupted JAR, that could explain your problem.
在我的绳索结束时,我考虑了我认为极不可能的可能性——JAR 不知何故损坏了——这一次直接转到项目下载页面以获取新副本。在 Eclipse 中将 JAR 添加到构建路径时,我注意到它的结构与我之前的结构略有不同。然后我尝试运行它并且......它起作用了!因此,在极不可能下载损坏的 JAR 的情况下,这可以解释您的问题。
回答by Mike Foss
I ran into this issue as well. In my project, I wanted to package everything into a JAR file to make a stand-alone application.
我也遇到了这个问题。在我的项目中,我想把所有东西都打包成一个 JAR 文件来制作一个独立的应用程序。
The ClassNotFoundException was thrown because I forgot to add the library to my classpath in the MANIFEST.MF file. Adding the line "Class-Path: lib/sqlite-jdbc-3.7.15-M1.jar" to my MANIFEST.MF file solved the problem for me.
抛出 ClassNotFoundException 是因为我忘记将库添加到 MANIFEST.MF 文件中的类路径中。将“Class-Path: lib/sqlite-jdbc-3.7.15-M1.jar”行添加到我的 MANIFEST.MF 文件中为我解决了这个问题。