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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2818075/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:13:17  来源:igfitidea点击:

Eclipse does not refresh project files in package explorer view

javaeclipse

提问by EugeneP

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. 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. Today even if there was a compile mistake, it would run fine. So I guess it does not recompile the class.

首先,当我运行一个 main 函数时,它运行一个以前编译的版本。假设我在窗口中按 Ctrl+F11 并打开一个 java 类和现有的 main 函数。通常它会重建类并运行新版本。今天即使有编译错误,它也能正常运行。所以我猜它不会重新编译这个类。

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. They remain of grey color if there were not any errors.

接下来,更奇怪的是,如果我故意在代码中犯了一个错误,而 Eclipse 用红色强调了这些行,项目资源管理器仍然没有将它们标记为包含错误。如果没有任何错误,它们将保持灰色。

First I did not know how to solve this problem. I tried to reopen the project, restart Eclipse and finally reboot the OS. After the tenth attempt, after rebooting, Eclipse said that all project's files are "OUT OF SYNC with the file system". When I pressed "Refresh" - F5 on a project's header name in Project Explorerit finally marked all the files with errors as containing errors and running the main function gave the desired result.

首先我不知道如何解决这个问题。我尝试重新打开项目,重新启动 Eclipse,最后重新启动操作系统。第十次尝试后,重新启动后,Eclipse 说所有项目的文件都“与文件系统不同步”。当我在项目资源管理器中的项目标题名称上按“刷新”-F5 时,它最终将所有有错误的文件标记为包含错误,并运行主函数给出了所需的结果。

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.

一个小时的工作过去了,这又发生在另一个项目上。全部都一样。没有将文件标记为红色,无论什么旧版本的类都运行,没有编译错误。

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?

你能提出什么建议?

采纳答案by Stephen C

When you select a project in the Project Explorer view and press F5, Eclipse shouldtraverse the entire directory tree for the project checking that all files and directories all in sync. It does for me ...

当您在 Project Explorer 视图中选择一个项目并按 F5 时,Eclipse应该遍历该项目的整个目录树,检查所有文件和目录是否同步。它对我...

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 通常对我有用。)

回答by tjin

Is Build automatically on? (Menu > Project > Build automatically)

是否自动构建?( Menu > Project > Build automatically)

回答by Abhijeet Kashnia

It happened to me because there was a cyclic dependency between two projects. Each project had the other on its build path.

发生在我身上是因为两个项目之间存在循环依赖。每个项目在其构建路径上都有另一个。

回答by Lucky

Solution: Reimport the project

解决方案重新导入项目

It happened to me when checking out a new file from svn in explorer. Eclipse could not find the new file for some reason.

在资源管理器中从 svn 检出新文件时发生在我身上。由于某种原因,Eclipse 找不到新文件。

I tried refreshing the project(F5) and Project > Cleanand 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). Make sure you unselect "Delete project contents on disk(cannot be undone)" checkbox and save any unsaved changes before you do this.

所以我从 Project Explorer 视图中删除了该项目(不是从硬盘中)。在执行此操作之前,请确保取消选中“删除磁盘上的项目内容(无法撤消)”复选框并保存所有未保存的更改。

Now reimport the project using File > Importoption. That should work in most cases.

现在使用File > Import选项重新导入项目。这应该在大多数情况下有效。