I want to iterate over a list of jars (undefined number) and add them all to the jar file. To add them I plan to use something like this:
<jar id="files" jarfile="all.jar">
<zipfileset src="first.jar" includes="**/*.java **/*.class"/>
<zipfileset src="second.jar" includes="**/*.java **/*.class"/>
</jar>
but how do I iterate over them? I don't have ant-contrib
Thanks!
Just use zipgroupfileset
with the Ant Zip task
<zip destfile="out.jar">
<zipgroupfileset dir="lib" includes="*.jar"/>
</zip>
This will flatten all included jar libraries' content.
If you do not have access to ant-contrib
For
task, you may end up to have to define your custom Task for doing what you need...
If you have ant1.6
and above, you can also try subant
(see New Ant 1.6 Features for Big Projects):
If you use
<subant>
'sgenericantfile
attribute it kind of works like<antcall>
invoking a target in the same build file that contains the task.
Unlike<antcall>
,<subant>
takes a list or set of directories and will invoke the target once for each directory setting the project's base directory.This is useful if you want to perform the exact same operation in an arbitrary number of directories.
来源:https://stackoverflow.com/questions/658561/ant-iterate-over-files