leeand00
leeand00

Reputation: 26392

How do you load a file into a variable in ant using the 'loadfile' task?

I'm trying the following and it doesn't seem to work.

<property name="file.configs.txt" value="" />
...
<target name="...">
   <loadfile property="file.configs.txt" srcFile="remoteConfig/configs.txt" />
</target>

I read here that the <loadfile> task is supposed to load the contents of a file into the specified property.

Upvotes: 9

Views: 15828

Answers (2)

seth
seth

Reputation: 37267

Get rid of the property definition line. Properties are immutable.

 <project name="foobar" default="foo">
   <target name="foo">
     <loadfile property="foo.bar" srcFile="foobar/moo.txt"/>
     <echo>${foo.bar}</echo>
   </target>
 </project>

Upvotes: 16

Nate
Nate

Reputation: 2456

Properties are immutable in Ant. The first definition of file.configs.txt will prevent it from being set again.

From: http://ant.apache.org/manual/Tasks/property.html

Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables.

Upvotes: 11

Related Questions