Eclipse ClassNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5044343/
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 ClassNotFoundException
提问by user12384512
Everything works fined, but suddenly eclipse stopped execute and junit tests or even main method, when i run them using run as - > Java application, run as -> junit test
一切正常,但是当我使用 run as -> Java application,run as -> junit test 运行它们时,Eclipse 突然停止了执行和 junit 测试甚至 main 方法
It simply throws error
它只是抛出错误
Caused by: java.lang.ClassNotFoundException: package.ClassName
whene ClassName - is class from where i trying to run method main. It affect only one of my projects ... Different workspaces works fine, other project in same workspace works fine as well.
何时 ClassName - 是我尝试运行方法 main 的类。它只影响我的一个项目......不同的工作区工作正常,同一工作区中的其他项目也工作正常。
I'm sure if i recreate current project, error will gone. But the adjustments of this project in eclipse is really hard, so i want to avoid it.
我确定如果我重新创建当前项目,错误就会消失。但是这个项目在eclipse中的调整真的很难,所以想避免。
Any clue?
有什么线索吗?
回答by jitm
The ClassName
is not in the Class Path, if you start from console you should use -cp
parameter , if from eclipse, please add ClassName
to the sources of current(start) project.
该ClassName
不是在类路径,如果你从控制台启动,你应该使用-cp
的参数,如果在Eclipse中,请添加ClassName
到当前(起始)项目的源代码。
回答by user12384512
Ok, I finally figured it out. The problem was with installed JRE in eclipse setting. I was playing around with this setting and changed installed JRE to JDK, and for some reason it broke the eclipse project.
好吧,我终于想通了。问题在于在 eclipse 设置中安装了 JRE。我在玩这个设置并将安装的 JRE 更改为 JDK,由于某种原因它破坏了 eclipse 项目。
回答by ClearCloud8
Thanks to adarshr, I was able to look at the Problems windowand determine that the build was failing because it could not find a class I had written.
感谢adarshr,我能够查看问题窗口并确定构建失败,因为它找不到我编写的类。
I had used the MS TFS pluginto create a "shelveset" and it was supposed to have removed my pending changes in the process. However, this integration with the TFS snapin and Eclipse is obviously not well implemented, since the Eclipse project still thought the file existed and was complaining that it could not be compiled.
我使用MS TFS 插件创建了一个“搁置集”,它应该已经删除了我在这个过程中的待定更改。但是,这种与 TFS 管理单元和 Eclipse 的集成显然没有很好地实现,因为 Eclipse 项目仍然认为该文件存在并抱怨无法编译。
I went and manually deleted those "files" or "non-existing files" from the Eclipse project (that I thought I had removed with the shelveset action) and the problem was solved.
我去手动删除了 Eclipse 项目中的那些“文件”或“不存在的文件”(我以为我已经用搁置集操作删除了这些文件),问题就解决了。
Also....
还....
Another annoying things is that the Tomcat error I was getting by trying to debug within Eclipse was like this:
另一个烦人的事情是我尝试在 Eclipse 中调试时遇到的 Tomcat 错误是这样的:
SEVERE: Error configuring application listener of class com.CompanyName.ProjectName.servlet.StartupConfigListener java.lang.ClassNotFoundException: com.CompanyName.ProjectName.servlet.StartupConfigListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
严重:在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643) 配置 com.CompanyName.ProjectName.servlet.StartupConfigListener java.lang.ClassNotFoundException 类的应用程序侦听器时出错:com.CompanyName.ProjectName.servlet.StartupConfigListener )
In reality, there was no problem at all with StartupConfigListener.java!! The build failed due to the OTHER problems I mentioned above, and therefore I guess this was the first class it attempted to load and failed.... because the entire project hadn't been able to compile perhaps?
实际上,StartupConfigListener.java 完全没有问题!!由于我上面提到的其他问题,构建失败,因此我猜这是它尝试加载的第一个类,但失败了......因为整个项目可能无法编译?
(Here's to hoping my next project is using Visual Studio instead of Eclipse!)
(希望我的下一个项目是使用 Visual Studio 而不是 Eclipse!)
回答by WhyGeeEx
You can also try going back to the basics. Check your command line and VM args. I've had this situation where a VM arg I was passing in was a path to a file that had a space in the path, and I had forgotten to include the full path in quotes. So e.g., if my arg looked something like
您也可以尝试回归基础。检查您的命令行和 VM 参数。我遇到过这种情况,我传入的 VM arg 是路径中包含空格的文件的路径,而我忘记在引号中包含完整路径。所以例如,如果我的 arg 看起来像
-DFILE=C:\Documents and Settings\myfile
...I'd get a java.lang.NoClassDefFoundError caused by a java.lang.ClassNotFoundException.
...我会得到一个由 java.lang.ClassNotFoundException 引起的 java.lang.NoClassDefFoundError。