views:

1430

answers:

2

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!

+2  A: 

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>'s genericantfile 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.

VonC
+3  A: 

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.

Vladimir
I tried this , and it works - But I encounter class not exist errors when I run the jar - it's as if it doesn't know they're there (but it does compile...)
yossale