如果您不想(或不能轻易)单独列出每个文件,一种解决方案是使用 Zip 任务,它允许嵌套<mappedresources>
(Ant 1.8.0+)。Zip 任务完成后,您可以使用 Jar 任务添加/更新清单和/或添加索引。
例如,假设除了想要
yay_my.jar
boo_my.jar
foo_my.jar
bar_my.jar
在输出 JAR 中,您还有一个目录stuff/
,其中包含一些文件和子目录。如果您想将 的内容stuff/
包含在 JAR 中,但又想stuff/subdir/*
添加为other_subdir/*
,请考虑以下事项:
<zip destfile="newjar.jar">
<zipfileset dir="yay" includes="my.jar" fullpath="yay_my.jar"/>
<zipfileset dir="boo" includes="my.jar" fullpath="boo_my.jar"/>
<!-- etc. -->
<mappedresources>
<fileset dir="stuff"/>
<compositemapper>
<globmapper from="subdir/*" to="other_subdir/*"/>
<identitymapper/>
</compositemapper>
</mappedresources>
</zip>
<!-- Update the newly-created ZIP in-place to add a basic manifest -->
<jar destfile="newjar.jar" update="true"/>
我测试了这个构建文件,它适用于 Ant 1.8.2。但是,如果在更改后 Ant 开始抛出 a NullPointerException
,请参阅Bug 54026。