java使用ANT根据包名动态生成JAR文件
我当前的构建文件有以下重复任务:
<jar jarfile="${build.lib}/${prefix}-foo.jar">
<fileset dir="${build.classes}">
<include name="com/a/c/foo/**"/>
</fileset>
</jar>
<jar jarfile="${build.lib}/${prefix}-bar.jar">
<fileset dir="${build.classes}">
<include name="com/a/c/bar/**"/>
</fileset>
</jar>
。。。等等。问题是构建。必须为每个新包或每个新子项目修改xml。这是我工作的地方经常发生的事
我想用基于“根”包动态生成JAR及其文件名的逻辑来代替它。例如,我可以将根包设置为com/a/c,该包下的所有包都会有自己的JAR。请注意,“foo”或“bar”下的所有包都只是“foo.jar”或“bar.jar”的一部分
我为ANT查找循环逻辑任务。我在ant contrib和JWare/AntXtras中都找到了一个,但这两个都无法按预期工作
# 1 楼答案
这个怎么样:
# 2 楼答案
我不知道如何循环查找所有包名,但可以使用宏来避免代码重复
我还没试过,但可以用