ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <>
Subject Re: Remove duplicate JAR file names from an XML file
Date Sat, 31 Jul 2010 12:50:43 GMT
-------- Original Message  --------
Subject: Re: Remove duplicate JAR file names from an XML file
From: Michael Ludwig <>
To: Ant Users List <>
Date: 31.07.2010 13:21

> Gilbert Rebhan schrieb am 31.07.2010 um 00:47 (+0200):
>> Whenever some kind of xml processing occurs within your ant workflow
>> i recommend the use of the xmltask[1].
>> From your first posting i assume you have some xml like :
>> <?xml version="1.0" encoding="UTF-8"?>
>> <jars>
>> <files>antlr-2.7.6.jar antlr-2.7.6.jar antlr-2.7.6.jar
>> aopalliance-1.0.jar aopalliance-1.0.jar aopalliance-1.0.jar
>> commons-validator-1.0.2.jar commons-validator-1.0.2.jar
>> commons-lang-2.2.jar commons-lang-2.2.jar</files>
>> </jars>
> If that is the OP's XML, poor design indeed.

sure, he didn't provide more details than =
I have an xml file which lists JAR file names in it with space
>specified as a delimiter.

> Should be using a regex here: getProperty("alljars").split("\\s+");
> That will take care of linebreaks and tabs, not only spaces.

not required in that case, as xmltask uses a blank as default
delimiter if not specified :
<xmltask source="./jars.xml">
<copy path="//files/text()"

>>   [xmltask] Cannot append values to properties
>>    ... don' get annoyed from those messages, simply ignore
>>    or do a search in the xmlproperty task sources and comment it out
> Why is it there in the first place? Appending to a property seems to
> work just fine, at least in this case.

from what i believe it's a warning because of backward compatibility,
should be in logged in debuglevel only.
Appending to Property works fine.

> While I like XML, I think it's overkill for a list of items. Here's a
> plain text example:

Maybe it's not his choice as he get's xml from an external tool !?

> michael@wladimir:~ :-) expand -t2 res.xml
> <project>
>   <file file="res.txt" id="input"/>
>   <union id="tokens">
>     <sort>
>       <tokens>
>         <resources refid="input"/>
>         <stringtokenizer/>
>       </tokens>
>     </sort>
>   </union>
>   <pathconvert refid="tokens"
>     pathsep="${line.separator}"
>     property="tokens2" />
>   <echo message="${tokens2}"/>
> </project>
> michael@wladimir:~ :-) ant -f res.xml 
> Buildfile: T:\cygwin\home\michael\res.xml
>      [echo] antlr-2.7.6.jar
>      [echo] aopalliance-1.0.jar
>      [echo] commons-lang-2.2.jar
>      [echo] commons-validator-1.0.2.jar
> Total time: 0 seconds
> -------------------------
> Can any of it be simplified further?

yep, you're right, i forgot rescources as usual,
had been with ant 1,6,5 much too long ;-)

i would write it that way =

<?xml version="1.0" encoding="UTF-8"?>
<!-- Import XMLTask -->
 <taskdef name="xmltask"

<target name="depends">
<xmltask source="./jars.xml">
<copy path="//files/text()"

<pathconvert property="uniquejars" pathsep=",">
    <propertyresource name="alljars"/>


<target name="main" depends="depends">
 <echo>$${uniquejars} = ${uniquejars}</echo>
 <echo>$${alljars} = ${alljars}</echo>


if you like perl, you may like (j)ruby or groovy
for scripting in ant <script ../> <scriptdef ../>
Sometimes it's easier to write a small script before
using too much clumsy xml or writing a new task.

Also try ant-flaka [1], which aims to simplify writing ant files.
i just started using it, and it rocks :-)

Regards, Gilbert


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message