我使用Ant 1.7,希望从不同的路径复制文件(它们没有关系,因此我不能使用包含选择器将它们从根目录中筛选出来)。我尝试在<copy>中使用<copy>而不是<fileset>,因为使用<path>,我可以指定在<fileset>中不可能的多路径。我的蚂蚁脚本看起来像这样,但不起作用。
<target name="copytest">
<!-- copy all files in test1 and test2 into test3 -->
<copy todir="E:/test3">
<path>
<pathelement path="C:/test1;D:/test2"></pathelement>
</path>
</copy>
</target>有人知道如何在<path>内部使用<copy>吗?或者可能有人有关于如何在没有选择器的情况下从不同来源复制文件的建议?
顺便说一句,我不想硬编码源目录,它们将从一个属性文件中读取,因此不应该考虑在<copy>中编写多个<copy>。
提前谢谢!
发布于 2011-08-08 12:44:35
<pathelement>通常使用它的path属性作为对classpath或其他预定义位置的引用,如果您想给出类路径之外的特定文件位置,尝试使用location属性
<pathelement location="D:\lib\helper.jar"/>location属性指定相对于项目的基本目录(或绝对文件名)的单个文件或目录,而path属性则接受冒号或分号分隔的位置列表。path属性用于预定义的路径--在任何其他情况下,应该首选具有位置属性的多个元素。
发布于 2017-01-03 16:39:52
发布于 2013-12-13 11:46:57
我们也有同样的问题
更复杂的是,我们需要向每个从路径转换的文件集中添加一个指定的模式集。
例如,这是传入的数据
<path id="myDirList" path="C:/test1;D:/test2" />
<patternset id="myPatterns" includes="*.html, *.css, etc, " />我们写了一个脚本来解决这个问题。
<resources id="myFilesetGroup">
<!-- mulitiple filesets to be generated here
<fileset dir="... dir1, dir2 ...">
<patternset refid="myPatterns"/>
</fileset>
-->
</resources>
<script language="javascript"><![CDATA[
(function () {
var resources = project.getReference("myFilesetGroup");
var sourceDirs = project.getReference("myDirList").list();
var patterRef = new Packages.org.apache.tools.ant.types.Reference(project, "myPatterns");
for (var i = 0; i < sourceDirs.length; i++) {
var fileSet = project.createDataType("fileset");
fileSet.dir = new java.io.File(sourceDirs[i]);
fileSet.createPatternSet().refid = patterRef;
resources.add(fileSet);
}
})();
]]></script>现在,您可以在复制任务中使用这些资源。
<!-- copy all files in test1 and test2 into test3 -->
<copy todir="E:/test3">
<resources refid="myFilesetGroup">
</copy>https://stackoverflow.com/questions/6979111
复制相似问题