167

Eclipse (3.4.2 with PyDev) deals with out-of-sync resources (files that have been edited outside of the IDE) differently from other IDEs that I've used, where only resources with editors open are considered out-of-sync. In Eclipse, any resource can go out of sync.

This means that when I perform a search after any file has changed outside of Eclipse, I get an error dialog telling me that files are out of sync, even if they have no open editors. As far as I can tell, there is no global refresh command, so I'm forced to read the project names (I have several projects) in the error dialog, and do a right-click + refresh for each of them.

I've checked the Refresh Automatically setting in Settings > General > Workspace, but this has no effect. Is there any way to get Eclipse to always just load non-active resources from disk?

DNS
  • 37,249
  • 18
  • 95
  • 132
  • Up to date answer for Eclipse 3.7+ is in 2nd answer. – Paul Verest Nov 25 '13 at 13:14
  • You can even sync with remote files using the remote system explorer (RSE) – Christophe Roussy Dec 16 '15 at 11:44
  • 2
    Possible duplicate of [eclipse, refresh files edited by external editor](http://stackoverflow.com/questions/13470311/eclipse-refresh-files-edited-by-external-editor) – Boris Lopez Feb 22 '17 at 15:38
  • @Boris, this question was asked several years earlier. The [other](http://stackoverflow.com/questions/13470311/eclipse-refresh-files-edited-by-external-editor) should be marked as a duplicate of *this* one. – Glenn Slayden Feb 22 '17 at 21:57

13 Answers13

201

This issue will be fixed in Eclipse 3.7 (Indigo). While "Refresh Automatically" does eventually bring resources back into sync, the refresh hook only exists for Windows, so on Linux and Mac OS it has to poll the filesystem periodically.

From 3.7 there's a new preference Settings > General > Workspace > Refresh On Access (aka Lightweight Refresh). This preference causes Eclipse to automatically refresh resources when it discovers that they're 'out-of-sync'. When opening, reading or searching files, it'll prevent out-of-sync errors from occurring.

See also: https://bugs.eclipse.org/303517

James Blackburn
  • 4,492
  • 2
  • 27
  • 24
  • 64
    It boggles the mind that this is an *option*. I have never not refreshed my out-of-sync files. – Christoffer Hammarström Dec 06 '11 at 20:24
  • 19
    :( I fought long and hard against making it an option. You're right, it's crazy. – James Blackburn Dec 07 '11 at 11:47
  • 6
    And if you want this option to be the default in Eclipse 3.8 / 4.2 vote here: http://bugs.eclipse.org/340977 – James Blackburn Mar 06 '12 at 13:49
  • 5
    I use IntelliJ IDEA though. I never have to worry about saving files, because they're saved automatically. It just works. If a file changes on disk it changes in the IDE. When there's a conflict it warns you and allows you to diff and merge. If worse comes to worst it has Local History so you can always revert to a few minutes ago. – Christoffer Hammarström Mar 06 '12 at 14:20
  • You could post a link in that Bugzilla issue to this page. – Christoffer Hammarström Mar 06 '12 at 14:27
  • One thing that causes problems for me is that Eclipse seems to do this automatic refresh even when its not in the foreground. I created a SO question on that - http://stackoverflow.com/questions/13595827/is-there-a-way-to-ge-eclipse-to-not-refresh-workspace-when-its-in-background – studgeek Nov 28 '12 at 00:38
  • I'd just like to add that it's Window > Preferences > Settings > General > Workspace > Refresh On Access On eclipse 3.7.2 – Sojurn Feb 02 '13 at 05:35
  • In my Kepler instance on OSX 10.9.2, the "Resource is out of sync error" can still occur. If I touch a project resource in a shell then try to Refactor->Rename the project, it triggers the error. It seems like Eclipse then refreshes the project because on subsequent attempts the Rename operation goes fine. – David Mann May 12 '14 at 15:09
  • 1
    @ChristofferHammarström: Eclipse also has a local history: Right-click in the file editor > Compare with > Local History. – ccpizza Jan 23 '15 at 09:37
  • Even with _Refresh on Access_ enabled, Eclipse (4.4.1) still won't show newly added files, so you still need to do a manual refresh. Looks like only file modifications are detected, but not directory structure changes. – ccpizza Jan 23 '15 at 09:41
  • @ccpizza: The point was that with IDEA files are automatically saved, and i don't have to worry about anything getting lost because of the local history. – Christoffer Hammarström Jan 23 '15 at 09:44
  • It still doesn't seem to work in my case. Perhaps because my project is loaded on a HPC? Any idea on how to fix this? Essentially my project is in a network drive, or server. – sam wolfe Oct 31 '22 at 10:51
28

I think if you click on the project node in the Project Explorer and press F5 or right click and select Refresh, all resources for that project will be refreshed. Also, if you CTRL+click on multiple projects, you should be able to refresh multiple projects at the same time.

A single click on a project, a CTRL+A to select everything, and an F5 should do exactly what you need - refresh everything.

I'll have to test this when I get the chance, but I believe this is how I overcame similar problems in the past.


I've noticed that this answer routinely is getting down voted. I'd like to point out that the question refers to a specific version of Eclipse: 3.4.2. There was actually no automatic method to refresh out-of-sync resources until version 3.7 Indigo of Eclipse, as mentioned in James Blackburn's answer. The method described in this answer is the only method to achieve this in version 3.4.2 (and any other version before 3.7 Indigo).

Community
  • 1
  • 1
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
  • 13
    Note that refreshing multiple selected projects will not work if any of them are closed - you need to deselect closed projects first. Alternatively, when *no* projects are selected in the Package Explorer or Navigator views pressing F5 will refresh all open projects (ctrl-click to deselect, clicking on empty space doesn't work). – Tom Clift Jul 16 '10 at 01:08
  • 71
    No offense to anyone, but why is the accepted answer to a question about how to get Eclipse to do something automatically a description of how to do it manually? – Srekel Jun 24 '11 at 14:50
  • 11
    @Srekel Because at the time of posting, this was the only method to do what @DNS wants to do. Based on @James Blackburn's more recent answer, there was an issue that was actually reported and corrected well after this question was originally posted. With more recent versions of Eclipse, this answer is not correct. However, the question specifically cites Eclipse 3.4.2 - this is the method of solving the problem presented in the question. – Thomas Owens Jun 24 '11 at 16:30
25

Out of synchronization problem is common in eclipse IDE so you have to check this option windows -> preference -> Workspace -> refresh using native hooks or polling.

DON
  • 835
  • 1
  • 8
  • 21
  • 7
    I believe this is currently the correct answer, at least since Eclipse Mars. – Henno Vermeulen Feb 26 '16 at 09:34
  • 2
    This checkbox doesn't work for me on Eclipse 4.5 on Ubuntu 14.04. After external change of file Eclipse doesn't see it until I open this file in Eclipse or make the Refresh. So the browser doesn't see the update of `.css` file for example if I update this file from external editor while running the server app from eclipse. To fix this I used [this plugin](https://github.com/psxpaul/EclipseJava7Refresher) which makes the checkbox actually work. See [this answer](http://stackoverflow.com/a/16184117/758991). – Ruslan Stelmachenko Dec 07 '16 at 15:26
  • This is working option for the version `Neon.3 Release (4.6.3)` – Kimchi Man Sep 28 '17 at 22:20
  • In Neon.3 on Mac, the option is in Preferences > General > Workspace > Refresh using native hooks or polling. – jmelvin Feb 18 '18 at 16:36
6

Eclipse Helios possesses a built in refresh feature at Preferences > General > Workspace. It's in the same spot where you disable automatic builds. Select refresh automatically. A plugin with the same functionality is Andrei Loskutov's Filesync Plugin. The update site address is: http://andrei.gmxhome.de/eclipse/. During installation, select Eclipse 3.5-3.7 plugins > FileSync.

user466206
  • 61
  • 1
  • 2
5

The global refresh actually exists in plain Eclipse without any plugins and without selecting every project in your workspace.

Basically you need to deselect everything in your project explorer and hit F5. To do that Ctrl+click the selected resource in the project explorer and hit F5.

5

Given that Java 7 has an api for filesystem hooks, one would think that refresh could be handled better in Eclipse.

Edit: Actually, there is a plugin that uses this mechanism: https://github.com/psxpaul/EclipseJava7Refresher

bronsted
  • 51
  • 1
  • 4
  • Thanks for the plugin. Without it my Eclipse on Ubuntu doesn't see the external changes of the files even when "Window->Preferences->General->Workspace->Refresh using native hooks or polling" is enabled. – Ruslan Stelmachenko Dec 07 '16 at 15:22
  • This plugin works great even on Eclipse 2020-12 . On MacOS (Big Sur) and also Catalina it refreshes too slow. With this plugin changes in external Editor (VSCode) take about 4sec to trigger a refresh / rebuild in Eclipse for me. – Christoph Feb 22 '21 at 19:27
  • There is a Eclipse bug addressing the native refresh on MacOS and Windows: https://bugs.eclipse.org/bugs/show_bug.cgi?id=108697 it seems pretty close. – Christoph Feb 22 '21 at 19:49
4

There is a global refresh - have nothing (or everything) selected in the package explorer and press F5 (or right-click on empty space and select Refresh). Of course, this could take rather long if you have large projects.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
3

A global refresh is really missing in Eclipse. The above procedure with selecting all projects and then running refresh (e.g. F5) does not work if you have closed projects included in your selection. This means, if you have 1/2 of your many projects closed as I do, you find yourself manually Ctrl-clicking through your dozens of projects. This is quite painful. I wish Eclipse would simply ignore closed projects.

Karol
  • 31
  • 1
2

Perhaps you should add a feature request on the eclipse site:

https://bugs.eclipse.org/bugs/

I think it would be a great idea to add a preference for automatically refreshing out of date resources.

2

Yes, Refresh on Access is long overdue ... those answers to this and similar enquires usually suggested enabling the global auto-refresh, which could take an age for large remote projects. In fact there are those who would say that Refresh on Access should have been the original (< 3.x) default behaviour ...

MikeW
  • 5,504
  • 1
  • 34
  • 29
2

I managed to solve this by creating a new "external tool" run config that executes a blank batch file. In the run config, you can have it refresh the workspace when complete. Then I created a macro using Practically Macro that 1) executes the last external tool run config (refreshing the workspace), then 2) executes the last debug run config (running my app). If you uncheck "Allocate console" then the completed external tool entry won't show up in the debug window.

NateS
  • 5,751
  • 4
  • 49
  • 59
1

Even if the solutions proposed by others perso are indeed correct, you have a "Refresh All" plugin for Eclipse. Simply add the Update page to your Eclipse list of update sites to install it in your IDE.

Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273
0

For Starting up there is an option to automatically refresh files in

Window -> Preferences -> General -> Startup and Shutdown -> Refresh workspace on startup

Click it in order to have a "fresh" start in eclipse. :)

Version: Eclipse 4.12

loved.by.Jesus
  • 2,266
  • 28
  • 34