本文介绍了Ant 将内容发布到不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 java 项目和一个 ANT 脚本来构建,然后使用简单的复制命令将该项目分发给其他项目.

I have a java project and an ANT script to build and then distribute the project to other projects with a simple copy command.

我只想在 ant 脚本的标题中将复制到文件的位置命名为一次,并且对于依赖于该项目的每个项目都没有明确的复制任务.

I would like to only name the place where to copy to files to once in the header of the ant script, and not have an explicit copy-task for every project that is dependent on this project.

我在 ANT 中找不到任何类似数组的东西,那么将某些内容分发到多个目录的最简洁方法是什么?

I can't find anything like arrays in ANT, so what would be the cleanest way of distributing something to multiple directories?

推荐答案

根据我在 Martin 的回答下的评论,我想发布我的解决方案版本作为另一种选择.我正在使用 Martin 回答中的属性名称来说明这一点.

According to what I commented under Martin's answer, I'd like to post my version of solution as another choice. And I am using property names from Martin's answer to make it clear.

<target name="deploy" >
    <property name="dest.dirs" value="/dir/one,/dir/two,/dir/thr/ee" />
    <for list="${dest.dirs}" param="dest.dir" parallel="true" delimiter="," >
        <sequential>
            <copy todir="@{dest.dir}" >
                <fileset dir="${srd.dir}" />
            </copy>
        </sequential>
    </for>
</target>

请注意,for"是一个 Ant-Contrib 任务,它在后面使用的是 Macrodef,因此您应该使用 @{} 来引用dest.dir";dest.dirs"将被分隔符分割成一个列表(可能是 String[]).这里我们使用逗号来分割它(分隔符的默认值为逗号).我还加了parallel",让它同时拷贝文件到所有的dest.dirs",但是,如果要拷贝的项目比较大,应该删除parallel".

Please note that "for" is an Ant-Contrib task, and it's using Macrodef in the back so you should use @{} to refer to "dest.dir"; the "dest.dirs" will be splited into a list (maybe String[]) by delimiter. Here we use comma to split it (and the default value to delimiter is comma). I also added "parallel" to make it copy files to all the "dest.dirs" at same time, however, if the project to copy is large, you should delete "parallel".

请查看http://ant-contrib.sourceforge.net/tasks/任务/for.htmlhttp://ant-contrib.sourceforge.net/tasks/tasks/foreach.html 了解更多信息.

Please check http://ant-contrib.sourceforge.net/tasks/tasks/for.htmland http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html for more information.

这篇关于Ant 将内容发布到不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:39
查看更多