1

I'm creating a web-app using Spring MVC. This app creates some images and saves them into a directory located in the webapp directory and then returns a view like the following:

<table>
  <tbody>
    <tr>
       <td><IMG SRC="http://locahost:8180/app/images/image1.png"></IMG></td>
       <td><IMG SRC="http://locahost:8180/app/images/image2.png"></IMG></td>  
    </tr>
  </tbody>
</table>

The problem is I'm not getting the images, I have to do a refresh on Eclipse to get those images. Any ideas?

Martin
  • 215
  • 5
  • 14
  • 1
    Any files you generate exist in the file system, but are not displayed in Eclipse until you refresh (F5). – Gilbert Le Blanc Dec 04 '14 at 22:10
  • Is there anyway to refresh programmaticaly after adding some new files? – Martin Dec 04 '14 at 22:13
  • 1
    you could program your fingers to push F5 XD – nLee Dec 04 '14 at 22:19
  • [**This**](http://blog.pengoworks.com/index.cfm/2008/6/30/Refreshing-Eclipse-Workspace-using-ANT) should help you or [**this SO answer**](http://stackoverflow.com/a/5468283/3928341) – nem035 Dec 04 '14 at 22:22

1 Answers1

1

Ok so to elaborate more on the links I put in the comments.

I stumble upon two ways of doing what you need (didn't actually do them but they seemed to work for others):

1) Refreshing Eclipse Workspace using ANT (Answer Link)

As stated in the link, Eclipse provides several ant tasks that you can use for various purposes, one of which is the <eclipse.refreshLocal /> tag:

<eclipse.refreshLocal resource="MyProject/MyFolder" depth="infinite"/>
  • resource is a resource path relative to the workspace
  • depth can be one of the following: zero, one or infinite

Furthermore, if you get a BUILD FAILED error, make sure you aren't running ANT outside of the Eclipse JRE. To fix this, go open up the External Tools Dialog (Run > External Tools > Open External Tools Dialog...) and make sure the JRE tab is set to "Run in the same JRE as workspace."

2) Refreshing Eclipse workspace programmatically using the IResource.refreshLocal() API (Answer Link)

As stated in the linked answer, you can do this at project root, a particular folder or an individual file.

To refresh all projects in a workspace, simply enumerate all projects using ResourcesPlugin.getWorkspace().getRoot().getProjects() API and refresh each in turn.

Here is another example (from the API website) that sets the contents of a file using a FileOutputStream, and then uses refreshLocal to synchronize the workspace.

   private void externalModify(IFile iFile) throws ... {
      java.io.File file = iFile.getLocation().toFile();
      FileOutputStream fOut = new FileOutputStream(file);
      fOut.write("Written by FileOutputStream".getBytes());
      iFile.refreshLocal(IResource.DEPTH_ZERO, null);
   }
Community
  • 1
  • 1
nem035
  • 34,790
  • 6
  • 87
  • 99