Eclipse:项目未构建,因为源文件...无法读取
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10786594/
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: The project was not built since the source file ... could not be read
提问by rwst
When compiling my Java project, I get this error in Other errors:
编译我的 Java 项目时,我在其他错误中收到此错误:
Description Resource Path Location Type
The project was not built since the source file /PROJECT/src/main/org/../ABC.java could not be read PROJECT Unknown Java Problem
Indeed, the file is listed in Package Explorer but shows only "Error retrieving content description. On the file system, the silent dir exists but not the file; git status is missing nothing. How do I resolve that compile error?
实际上,该文件在包资源管理器中列出,但仅显示“检索内容描述时出错。在文件系统上,静默目录存在但文件不存在;git status 什么也没有丢失。我该如何解决该编译错误?
回答by Nerrve
Simply restart eclipse, refresh all projects and do a clean build. That should fix it. Don't forget the eclipse restart, else no matter how many times you do a clean build or refresh, it will not fix the problem
只需重新启动 eclipse,刷新所有项目并进行干净的构建。那应该解决它。不要忘记重新启动eclipse,否则无论您进行多少次干净的构建或刷新,都无法解决问题
回答by Jeevan
Looks like someone has deleted that file but eclipse still think that file is part of the project. Might have happened when someone deleted a file from the source control in an improper way.
看起来有人删除了该文件,但 eclipse 仍然认为该文件是项目的一部分。当有人以不正确的方式从源代码管理中删除文件时,可能会发生这种情况。
If you dont have pending changes then you can get fresh copy of the project and import it into your workspace.
如果您没有挂起的更改,那么您可以获得项目的新副本并将其导入您的工作区。
If you have pending changes then take a copy of changes and repeat above step. ( A restart of eclipse may be necessary)
如果您有待处理的更改,请复制一份更改并重复上述步骤。(可能需要重新启动 eclipse)
回答by The Beast
It can be related to missing location Select File => properties => Resource => Edit file location.
它可能与缺少位置选择文件 => 属性 => 资源 => 编辑文件位置有关。
回答by Clay
For anyone using VS Code with the RedHat Java plugins (which use Eclipse tooling under the hood), I got this error as well. I fixed with the following:
对于将 VS Code 与 RedHat Java 插件(在幕后使用 Eclipse 工具)一起使用的任何人,我也收到此错误。我修复了以下内容:
# Quit VS Code
rm -rf ~/Library/Application\ Support/Code/User/workspaceStorage/*
# Reopen VS Code
回答by Campa
As all others said, it is most probably an issue with the internal caches of Eclipse.
正如所有其他人所说,这很可能是Eclipse内部缓存的问题。
I usually restart the IDE with the additional -clean
option to wipe out the OSGi-related caches, then cleanand rebuild all the projects.
我通常使用附加-clean
选项重新启动 IDE,以清除与 OSGi 相关的缓存,然后清理并重建所有项目。
If the problem persists, I realized that cleaning up the single affecting project works better that cleaning up the whole workspace. (Ominous... XD)
如果问题仍然存在,我意识到清理单个影响项目比清理整个工作区效果更好。(不祥……XD)
This usually happens to me when merging changes that imply renaming or deletion of source files, prior to launching Eclipse.
在启动Eclipse之前合并意味着重命名或删除源文件的更改时,这通常发生在我身上。
回答by Marc Johnson
I know the answer is accepted but in my case that solution didn't work for me, I had restored files from a backup to my local project in linux and the files I restored were owned by root with only the owner being able to read/write the files. SO, I sudo chowned the files "sudo chown _R myUser:myUser *" at the base of my project, refreshed in Eclipse (f5) and the annoying repeated failure of my build was a thing of the past.
我知道答案已被接受,但在我的情况下,该解决方案对我不起作用,我已将文件从备份恢复到 linux 中的本地项目,并且我恢复的文件归 root 所有,只有所有者能够读取/写文件。所以,我 sudo chown 文件“sudo chown _R myUser:myUser *”在我的项目的基础上,在 Eclipse (f5) 中刷新,我的构建的烦人的重复失败已经成为过去。
回答by YantingChen
If you are writing Maven projects, try right click on the project and select [Maven] -> [Update Project...] It works for me.
如果您正在编写 Maven 项目,请尝试右键单击该项目并选择 [Maven] -> [更新项目...] 它对我有用。
回答by Pete B.
For me there was a different solution than mentioned here.
对我来说,有一个与这里提到的不同的解决方案。
I was doing a no-no, I imported a project that had a .project file, and there was some errors in the way my version of eclipse was reading some of the files. The package names and files had a little ! symbol with a yellow background.
我做了一个不,我导入了一个具有 .project 文件的项目,并且我的 eclipse 版本读取某些文件的方式存在一些错误。包名和文件有一点!黄色背景的符号。
The solution was to delete the packages. Obviously make a backup. But in doing this most times the files nor the packages were deleted. Instead eclipse refreshed and the desired files were there. Sometimes I had to hit refresh (F5), and sometimes I had to restore files.
解决方案是删除包。显然要备份。但在大多数情况下,文件和软件包都被删除了。相反 eclipse 刷新并且所需的文件在那里。有时我不得不点击刷新(F5),有时我不得不恢复文件。
I found it best to delete the packages as that is where eclipse was having reading the data.
我发现最好删除包,因为这是 eclipse 读取数据的地方。
回答by Code ninetyninepointnine
If the missing file is still mentioned in the Linked Resources, no refresh and restart of Eclipse will ever solve the problem. You have to delete the file in the Project Properties Linked Resources list.
如果链接资源中仍然提到丢失的文件,则 Eclipse 的刷新和重新启动将永远无法解决问题。您必须删除 Project Properties Linked Resources 列表中的文件。