tags:

views:

33

answers:

3

I am trying to add a property to a .jad file in my ant build process.

Is there a task in ant to do this? All I need to do is add a line of text to the end of a text file but I cannot find a task to do this.

A: 

If you're running on Linux/Unix you can use the <exec> task to execute arbitrary shell scripts as follows:

<project name="test">
  <target name="append">
    <exec executable="/bin/bash">
      <arg value="-c"/>
      <arg value="echo HELLO >> app.jad"/>
    </exec>
  </target>
</project>

Running ant append will append "HELLO" to the file app.jad in this case.

Under Windows you need to invoke cmd instead:

<project name="test">
  <target name="append">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg value="echo HELLO >> app.jad"/>
    </exec>
  </target>
</project>

The -c and /c switches are important since this tells the shell to interpret the remainder of the command line as a single command to execute.

Richard Cook
See @Andrew Hubbs's own response for a more straightforward answer!
Richard Cook
+4  A: 

I believe this will work. Testing it now.

<concat append="true" destfile="app.jad">foo: bar</concat>
Andrew Hubbs
This is a much cleaner solution than mine. Upvoted!
Richard Cook
<concat append="true" destfile="app.jad">foo: bar</concat> Needed to add the append="true" or else it wipes the file and leaves only the added line.
Andrew Hubbs
+1  A: 

Another alternative, using the ant echo task

<echo file="app.jad" append="true">hello world
</echo>
Mark O'Connor