Friday, January 8, 2010

Ant goodies 1

Suppose you have a library project checked into subversion

library
|_apache
|_log4j
|_ log4j-1.2.15.jar

and you wanted to copy such library jars to your target dir when you kick an ant build

here is what I created!

[code]

            <findAndCopy fromdir="${master.library.dir}" todir="${lib.dir}" filenames="${project.classpath.compile}" />

where project.classpath.compile=log4j-1.2.15.jar,junit-4.7.jar

<macrodef name="findAndCopy">

<attribute name="fromdir" />

<attribute name="todir" />

<attribute name="filenames" />

<sequential>

<for list="@{filenames}" param="file">

<sequential>

<echo>iterate == '@{file}'</echo>

<copy todir="@{todir}" flatten="true">

<fileset dir="@{fromdir}" includes="**/*.jar">

<filename name="**/@{file}" />

</fileset>

</copy>

</sequential>

</for>

</sequential>

</macrodef>

[/code]

kewl

sweet!

oh, I do use ant-contrib, that is evil!

No comments:

Post a Comment