Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 859
leeand00 Avatar asked Aug 19 '09 19:08

leeand00


People also ask

Which task is used to load the file into a property in ant?

This task is used to load file into a property. It works on files and provides a srcFile attribute for ease. It uses default encoding current locale unless other one is specified.

How do you run an ant task?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.


2 Answers

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>
like image 161
seth Avatar answered Oct 03 '22 06:10

seth


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.

like image 45
Nate Avatar answered Oct 03 '22 07:10

Nate