ant iterate over files

有些话、适合烂在心里 提交于 2020-01-02 15:18:18

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/658561/ant-iterate-over-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!