Refreshing Eclipse Workspace using ANT

Posted by Dan on Jun 30, 2008 @ 12:49 PM

I was looking for a way to programmatically refresh some specific folders in my workspace anytime I ran my ANT script. Eclipse provides several ant tasks that you can use for various purposes, once 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

However, when I first tried adding this task to my ANT script, I was getting an error that looked like:

BUILD FAILED
c:\path\folder\build.xml:85: Problem: failed to create task or type eclipse.refreshLocal
Cause: The name is undefined.
Action: Check the spelling.

Needless to say, I was pretty confused. So after some brief research, it turns out I accidentally 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."

image

I'm not sure how that setting got changed, but I'm glad I found the fix. This also has sped up the first time execution of my ANT scripts.

Categories: HTML/ColdFusion, Java

14 Comments

  • Great find. Looks like you can do something similar with the "Refresh" tab on that dialog - you can "Refresh resources upon completion" and then there are several options for what to refresh - entire workspace, etc...
  • I wonder how to force a refresh if the ant update process is outside of Eclipse, such as I have a bat file to fire off updating my working copies. Interesing stuff.

    You might be able to do a test in the ant to see if it running inside eclipse like <target name="refreshResource" if="eclipse.refreshLocal" ...><eclipse.refreshLocal resource="MyProject/MyFolder" depth="infinite"/></target>
  • @Jim:

    You can do it that way, but I wanted to ecapsulate everything within the build script. That way if I ever need to branch the build file, everything is portable.

    @Mike:

    Eclipse sets a eclipse.running property to true when running inside Eclipse, so you can just check for that property if running outside of Eclipse. There's a pretty decent Eclipse/ANT FAQ here: http://eclipsewiki.editme.com/ANTFaq
  • These kind of problems is exactly why I created Groovy Monkey and am in the process of taking over Eclipse Monkey. Writing ant scripts using the AntBuilder in Groovy is almost a joy, and refreshing the workspace is so simple to do from a monkey script. You should give it a try. Of course as of right now, try Groovy Monkey, not Eclipse Monkey.
  • @James - got a link to Groovy Monkey?
  • Sure... sorry I did not include it earlier.
    The update site is at http://groovy-monkey.sourceforge.net/update/
    The main page is at http://groovy.codehaus.org/Groovy+Monkey

    Thanks for giving it a looksie :)
  • Running in an separate JRE is the default setting...so you did not change anything :-)
    The reason for the performance increase is you are reusing the Ant classes within an existing classloader and not having to reload all of the classes for each build. We changed several Eclipse versions ago to default to a separate JRE as it was just too easy for a rogue class or task within an Ant build to cause your Eclipse session to have problems when running in the same JRE: memory leaks, deadlocks etc. Same JRE execution is powerful but potentially dangerous :-)

    I would be interested to know why the Refresh tab functionality did not meet your needs?
  • @Darin:

    Mainly I wanted to do the refresh straight from ANT--that way I could easily port the script to other build projects and not have to worry about any additional settings. Also, I only needed to refresh a few select directories (this is a web project with lots of folders and thousands of files.) Being able to control the refresh programatically was just a better fit for my current needs.
  • Excellent information here. I spent a good deal of time trying to figure out why I was getting the errors I was seeing. Now if I could find any information on any ANT tasks for the Web Tools Platform, I'd be stoked!
  • What do you want to do with Ant? I've got a wiki page setup here: http://www.thecrumb.com/wiki/ant with lots of good info...
  • Thanks man, that would have taken me forever to figure out. Keep it up.
  • Thanks for this tip!
  • It solved my problem!
    Thanks, I was trying to solve this problem by adding different java packages.
  • Thank you for posting this!

Comments for this entry have been disabled.