the following simple target seems to hit the server twice. i have logged the http traffic with wireshark and it confirms that the http-call is sent (and received) twice. <project name="Test" default="recreate-via-http" > <target name="recreate-via-http"> <loadresource property="result" > <url url="http://someserver/somecall.php" /> </loadresource> <echo>${result}</echo> </target> </project>
as a user on stackoverflow points out, it seems that the problem is getting the length of the content first and then getting the actual content, resulting in two http calls. see: http://stackoverflow.com/questions/7284649/ant-loadresource-task-called-twice
The analysis is correct. For "local" resources the querying the size first is a nice optimization. Also, we don't set properties for resources of length 0 and don't need to read the resource in order to find out it is empty that way. There is no easy way for Ant to know whether a resource is a remote resource, it may have been wrapped in some sort of decorator like a gzipresource wrapped around an urlresource. The best we can probably do is adding an option to disable the size check. WRT the stackoverflow comments: The call to close() inside of the getSize method is strictly necessary as there will be many cases where only the size of a resource is asked for without actually reading the stream (just think of the size selector).
I'd love to see this fixed. I am trying to switch to ant for our deployment, but we reinitialize our web apps via a special URL. I need to call this after deployment. Calling it twice adds a delay and impacts the users. I don't understand the comments about why it's necessary to do it this way. If I call GET or wget on the command line those programs don't request my URL twice.