Eclipse 构建错误“未编写类文件。项目可能不一致,如果是这样,请尝试刷新此项目并构建它”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17154360/
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 Build Error "A class file was not written. The project may be inconsistent, if so try refreshing this project and building it"
提问by Sammy Guergachi
I have been struggling with a very weird issue that has suddenly popped up on the latest version of Eclipse Classic (4.2.2).
我一直在努力解决一个非常奇怪的问题,这个问题突然出现在最新版本的 Eclipse Classic (4.2.2) 上。
Everytime I try creating or refactoring a class or subclass in any of my projects (all Java) in my Eclipse workspace I get an error at the very top of my class that says
每次我尝试在我的 Eclipse 工作区中的任何项目(所有 Java)中创建或重构类或子类时,我都会在我的类的最顶部收到一条错误消息
A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
Again, this happens when I create new classes. And even when I rename current classes, then undo the renaming, its totally fine, but changing a single character in the name causes this error to happen for that specific class.
同样,当我创建新类时会发生这种情况。即使我重命名当前类,然后撤消重命名,这完全没问题,但是更改名称中的单个字符会导致该特定类发生此错误。
I have Auto Build on, and I tried multiple times to clean and refresh every project as well as restart Eclipse entirely.
我启用了 Auto Build,并且多次尝试清理和刷新每个项目以及完全重新启动 Eclipse。
I have literally no idea how to even start figuring out how to fix this. The solutions i've found through search didn't help, so i'm hoping I might find any clues here.
我真的不知道如何开始弄清楚如何解决这个问题。我通过搜索找到的解决方案没有帮助,所以我希望我能在这里找到任何线索。
采纳答案by Ganesh Satpute
I had the same problem and here's how I solved it in the end: It turned out that the disc space on the drive where workspace resides was full.
我遇到了同样的问题,这是我最终解决的方法:结果是工作区所在的驱动器上的磁盘空间已满。
Silly mistake but worth checking.
愚蠢的错误,但值得检查。
回答by user8574877
In my case, this was caused by the fact that the build output directories were owned by a different user, and Eclipse could not write into them.
就我而言,这是由于构建输出目录归其他用户所有,而 Eclipse 无法写入这些目录。
回答by Oualid Jabnoune
Clean your workspace by starting eclipse from the command line with the -clean argument :
通过使用 -clean 参数从命令行启动 eclipse 来清理您的工作区:
eclipse -clean
See also How to run eclipse in clean mode? and what happens if we do so?
回答by Richie_b
I had the same issues, the following worked for me:
我遇到了同样的问题,以下对我有用:
- Right click eclipse then running "as an Administrator"
- Click Project > Clean.
- 右键单击 eclipse 然后以“管理员身份”运行
- 单击项目 > 清理。
回答by sri
In my case this kind of error caused due to disk space got full and it got resolved by just freeing disk space where eclipse have been installed. That is c/d/e drivers.
在我的情况下,由于磁盘空间已满而导致的这种错误,只需释放安装了 eclipse 的磁盘空间即可解决。那是 c/d/e 驱动程序。
回答by Kapil Suri
I had the same issue on Mac OS X. I had a maven project.
我在 Mac OS X 上遇到了同样的问题。我有一个 Maven 项目。
Try running the following command on Terminal. This looks like an access issue.
尝试在终端上运行以下命令。这看起来像一个访问问题。
sudo mvn clean
Provide password for admin user.
为管理员用户提供密码。
Then open Eclipse and refresh your project.
然后打开 Eclipse 并刷新您的项目。
回答by gia
We are using Eclipse here too and have to handle a workspace with more than 200 plug-ins. Every now and then people have similar problems with their workspace and inconsistencies reported in a weird way by Eclipse. What people here usually do is (next step only in case previous step didn't help): - trying to ContextMenu->Team->Clean/Refresh the whole workspace - creating a new workspace and check out all necessary files from the repository - reinstalling Eclipse to a new directory
我们在这里也使用 Eclipse,并且必须处理包含 200 多个插件的工作区。人们时不时地会遇到类似的工作区问题以及 Eclipse 以一种奇怪的方式报告的不一致问题。这里的人们通常做的是(下一步仅在上一步没有帮助的情况下): - 尝试ContextMenu-> Team-> 清理/刷新整个工作区 - 创建一个新的工作区并从存储库中检出所有必要的文件 -将 Eclipse 重新安装到新目录
From my experience after using the Eclipse IDE on a daily basis for many years, it doesn't make very much sense to waste too much time with these issues, unless they aren't solved by one of the steps above. It takes too much time to struggle with these things, while starting from scratch is done in an hour or less (and usually fixes the issue). If your Eclipse still behaves strangely it might make sense to go through your installed plug-ins. Not all external plug-ins follow the Eclipse guidelines and can seriously harm the performance and operational consistency of your Eclipse installation (E.g. Sonar Plug-in, Toad Plug-in, ...)
根据我多年来每天使用 Eclipse IDE 后的经验,在这些问题上浪费太多时间并没有多大意义,除非通过上述步骤之一无法解决这些问题。处理这些事情需要花费太多时间,而从头开始只需一个小时或更短的时间(通常可以解决问题)。如果您的 Eclipse 仍然表现得很奇怪,那么检查您安装的插件可能是有意义的。并非所有外部插件都遵循 Eclipse 指南,它们会严重损害 Eclipse 安装的性能和操作一致性(例如声纳插件、Toad 插件……)
回答by Bret Hogg
I solved this problem by running Eclipse as root.
我通过以 root 身份运行 Eclipse 解决了这个问题。
回答by Alexander Gorbenko
Try to launch Eclipse as Administrator.
尝试以管理员身份启动 Eclipse。
回答by Prem
I had the same issue and it got fixed by running eclipse in administrator mode Eclipse Shortcut-->Right click-->More-->Run as Administrator
我有同样的问题,它通过在管理员模式下运行 Eclipse Eclipse Shortcut-->右键单击-->更多-->以管理员身份运行来解决