为什么 Eclipse 看不到库的 .jar 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2638446/
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
Why Eclipse does not see .jar file of a library?
提问by Roman
I have a java project in which I have "Referenced Libraries". In the "Referenced Libraries" I have a .jar file of a library that I use (I use only one external library).
我有一个 Java 项目,其中有“参考库”。在“参考库”中,我有一个我使用的库的 .jar 文件(我只使用一个外部库)。
When I try to "Run -> Run" the code I have a NullPointerException. From my previous experience I know that it it (very likely) because my code does not see the library.
当我尝试“运行 - > 运行”代码时,我遇到了 NullPointerException。根据我以前的经验,我知道它(很可能)是因为我的代码没有看到库。
I just started to use Eclipse and it can be the I do not "connect" libraries in a correct way. Should I use some options or additional action to force Eclipse to see the .jar file of the library?
我刚开始使用 Eclipse,它可能是我没有以正确的方式“连接”库。我应该使用一些选项或附加操作来强制 Eclipse 查看库的 .jar 文件吗?
ADDED:
添加:
By the right click on the library I get a drop-down menu in which I see "Build Path". My be I need to do something there?
通过右键单击库,我会得到一个下拉菜单,在其中我可以看到“构建路径”。我是我需要在那里做些什么?
回答by Bas
Have you tried this? http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
你试过这个吗? http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
Add the library's to your build path :]
将库添加到您的构建路径:]
回答by Jim Blackler
External JARs should be added with Java Build Path -> Libraries -> Add External JARs.
应该使用 Java Build Path -> Libraries -> Add External JARs 添加外部 JAR。
Generally the lack of wavy red lines under your class references will tell you Eclipse has recognised the JAR ok.
通常,您的类引用下缺少波浪形红线会告诉您 Eclipse 已识别 JAR 没问题。
Depending on your target type (you don't say) there may be additional steps to deploy the JAR.
根据您的目标类型(您没有说),可能需要额外的步骤来部署 JAR。
Many things can cause a NullPointerException. It would be useful to see the full error and callstack. In my experience, missing library content manifests as ClassNotFoundExceptions.
许多事情都可能导致 NullPointerException。查看完整的错误和调用堆栈会很有用。根据我的经验,缺少的库内容表现为 ClassNotFoundExceptions。
回答by Eran Medan
Are you sure it's the missing Jar?
你确定是丢失的 Jar 吗?
NullPointerException
will not usually happen if you have a missing jar
For that you may get a ClassNotFoundException
or MethodNotFoundException
NullPointerException
如果你有一个丢失的罐子,通常不会发生因为你可能会得到一个ClassNotFoundException
或MethodNotFoundException
Adding a breakpoint for NullPointerException in eclipse will tell you when it happened
在eclipse中为NullPointerException添加断点会告诉你它什么时候发生
回答by lfvv
For me it happened the case where I already added the JAR and Eclipse still did not notice them, then I went to project properties -> Java Build Path -> Libraries and removed wrong references.
对我来说,发生了这样的情况,我已经添加了 JAR 并且 Eclipse 仍然没有注意到它们,然后我去了项目属性 -> Java 构建路径 -> 库并删除了错误的引用。