简体   繁体   English

Eclipse 在 package 资源管理器视图中不刷新项目文件

[英]Eclipse does not refresh project files in package explorer view

Today I see a strange behaviour of Eclipse 3.5.2 for the first time in 3 months.今天我在 3 个月内第一次看到 Eclipse 3.5.2 的奇怪行为。

First, when I run a main function, it runs a previously compiled version.首先,当我运行 main function 时,它运行的是之前编译过的版本。 Let's say I press Ctrl+F11 in the window with an open java class and existing main function. Usually it rebuilds the class and runs a new version.假设我在打开 java class 和现有主要 function 的 window 中按 Ctrl+F11。通常它会重建 class 并运行新版本。 Today even if there was a compile mistake, it would run fine.今天即使有编译错误,也能正常运行。 So I guess it does not recompile the class.所以我猜它不会重新编译 class。

Next, more strangely, if I intentionally make a mistake in the code and Eclipse underlines those lines in red, still the project Explorer does not mark them as containing errors.接下来,更奇怪的是,如果我故意在代码中犯了一个错误,并且 Eclipse 将这些行用红色下划线,项目资源管理器仍然不会将它们标记为包含错误。 They remain of grey color if there were not any errors.如果没有任何错误,它们将保持灰色。

First I did not know how to solve this problem.首先我不知道如何解决这个问题。 I tried to reopen the project, restart Eclipse and finally reboot the OS.我试图重新打开项目,重新启动 Eclipse,最后重新启动操作系统。 After the tenth attempt, after rebooting, Eclipse said that all project's files are "OUT OF SYNC with the file system".第十次尝试后,重新启动后,Eclipse 说所有项目的文件都“与文件系统不同步”。 When I pressed "Refresh" - F5 on a project's header name in Project Explorer it finally marked all the files with errors as containing errors and running the main function gave the desired result.当我在Project Explorer中的项目名称 header 上按“刷新”- F5 时,它最终将所有有错误的文件标记为包含错误,并且运行主要的 function 给出了预期的结果。

An hour of my work passed and this happened again , with the other project.我的工作一个小时过去了,这又发生在另一个项目上。 All the same.全都一样。 No marking of files as red, running no matter what old version of class with no compile errors.没有将文件标记为红色,无论 class 是什么旧版本都可以运行,没有编译错误。

And since Eclipse does not tell that files are out of sync, simply pressing F5 on a project cannot help.由于 Eclipse 并不能说明文件不同步,因此仅在项目上按 F5 键无济于事。

What can you suggest?你有什么建议?

When you select a project in the Project Explorer view and press F5, Eclipse should traverse the entire directory tree for the project checking that all files and directories all in sync. 在Project Explorer视图中选择项目并按F5时,Eclipse 应该遍历项目的整个目录树,检查所有文件和目录是否同步。 It does for me ... 它对我有用......

The only thing I can think of that would cause this not to work is if you have file system timestamp anomalies. 我能想到的唯一一件事就是如果你有文件系统时间戳异常,那就不会起作用。 For example, if a file in the file system is updated but the file's last-modified shows that it was updated in the past. 例如,如果文件系统中的文件已更新,但文件的最后修改文件显示它在过去已更新。 This kind of thing can happen if your machine's system clock is moved backwards or forwards at an inconvenient time. 如果机器的系统时钟在不方便的时候向后或向前移动,就会发生这种情况。 If you think this might have happened, try closing all projects, restarting Eclipse and doing another F5 refresh. 如果您认为这可能已经发生,请尝试关闭所有项目,重新启动Eclipse并执行另一次F5刷新。

(I run into Eclipse synchronization issues a lot, but I put it down to a combination of flakey plugins and doing builds from the command line. Either F5 or Project>Clean usually works for me.) (我在Eclipse同步问题上遇到了很多问题,但我把它归结为flakey插件的组合,并从命令行进行构建。无论是F5还是Project> Clean通常都适用于我。)

Is Build automatically on? 是否自动生成? ( Menu > Project > Build automatically ) Menu > Project > Build automatically

It happened to me because there was a cyclic dependency between two projects. 它发生在我身上,因为两个项目之间存在循环依赖关系。 Each project had the other on its build path. 每个项目都有另一个在其构建路径上。

Solution : Reimport the project 解决方案重新导入项目

It happened to me when checking out a new file from svn in explorer. 当我从资源管理器中查看svn中的新文件时,它发生在我身上。 Eclipse could not find the new file for some reason. 由于某种原因,Eclipse无法找到新文件。

I tried refreshing the project( F5 ) and Project > Clean and build the project( Project > Build All ) none of these worked for me. 我尝试刷新项目( F5 )和Project > Clean并构建项目( Project > Build All )这些都不适合我。

So I deleted the project from the Project Explorer view(Not from hard disk). 所以我从Project Explorer视图中删除了项目(不是从硬盘中删除)。 Make sure you unselect " Delete project contents on disk(cannot be undone) " checkbox and save any unsaved changes before you do this. 确保取消选中“ 删除磁盘上的项目内容(无法撤消) ”复选框,并在执行此操作之前保存所有未保存的更改。

Now reimport the project using File > Import option. 现在使用File > Import选项重新导入项目。 That should work in most cases. 这应该适用于大多数情况。

If you use gradle, or something similar, instead of reimporting a project you can just regenerate the project files ( gradle eclipse for example), and then you can refresh the project.如果您使用 gradle 或类似的东西,而不是重新导入项目,您可以重新生成项目文件(例如gradle eclipse ),然后您可以刷新项目。 Less cumbersome than deleting and reimporting.比删除和重新导入更简单。

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

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