Refreshing Eclipse Workspace using ANT
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."
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.
Comments
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>
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
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 :)
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?
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.
Thanks, I was trying to solve this problem by adding different java packages.
