简体   繁体   English

Eclipse ClassNotFoundException

[英]Eclipse ClassNotFoundException

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 一切正常,但是当我使用运行方式-> Java应用程序,运行方式-> junit test运行它们时,日食突然停止了执行和junit测试甚至主要方法。

It simply throws error 它只是引发错误

Caused by: java.lang.ClassNotFoundException: package.ClassName

whene ClassName - is class from where i trying to run method main. whene ClassName-是我尝试运行方法main的类。 It affect only one of my projects ... Different workspaces works fine, other project in same workspace works fine as well. 它只影响我的一个项目...不同的工作区工作正常,同一工作区中的其他项目也工作正常。

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. 但是这个项目在日食方面的调整真的很难,所以我想避免它。

Any clue? 有什么线索吗?

ClassName不在类路径中,如果从控制台启动,则应使用-cp参数,如果从eclipse开始,请将ClassName添加到当前(开始)项目的源代码中。

Ok, I finally figured it out. 好吧,我终于明白了。 The problem was with installed JRE in eclipse setting. 问题是在日食设置中安装了JRE。 I was playing around with this setting and changed installed JRE to JDK, and for some reason it broke the eclipse project. 我正在使用此设置,并将已安装的JRE更改为JDK,由于某种原因,它破坏了eclipse项目。

Thanks to adarshr , I was able to look at the Problems window and determine that the build was failing because it could not find a class I had written. 多亏了adarshr ,我能够查看“ 问题”窗口并确定构建失败,因为它找不到我编写的类。

I had used the MS TFS plugin to create a " shelveset " and it was supposed to have removed my pending changes in the process. 我曾经使用MS TFS插件创建了一个“ shelfset ”,它应该删除了我在该过程中未完成的更改。 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. 但是,与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) 严重:配置类com.CompanyName.ProjectName.servlet.StartupConfigListener java.lang.ClassNotFoundException的应用程序侦听器时出错:org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643处的com.CompanyName.ProjectName.servlet.StartupConfigListener )

In reality, there was no problem at all with StartupConfigListener.java!! 实际上,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? 由于上面提到的其他问题,构建失败了,因此我想这是它尝试加载并失败的第一类。...因为整个项目可能无法编译?

(Here's to hoping my next project is using Visual Studio instead of Eclipse!) (这里希望我的下一个项目是使用Visual Studio而不是Eclipse!)

You can also try going back to the basics. 您也可以尝试回到基础知识。 Check your command line and VM args. 检查您的命令行和VM参数。 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. 在这种情况下,我传入的VM arg是指向文件的路径,该文件的路径中有空格,而我忘记了用引号将完整路径包括在内。 So eg, if my arg looked something like 因此,例如,如果我的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。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM