【问题标题】:Ant copy task ignoring filesAnt复制任务忽略文件
【发布时间】:2012-04-12 03:10:52
【问题描述】:

我有一个看似正确但复制不正确的 Ant 复制任务(在 Jenkins 构建调用的 Maven 脚本中定义)。任务定义为

<copy todir="./Virgo/config" overwrite="true" verbose="true">
    <fileset dir="${config.folder}">
        <include name="*.properties, *.xml" />
    </fileset>
</copy>

当我运行任务时,我可以看到指定了正确的目录,但是复制任务没有选择任何文件。源目录和目标目录都存在,我没有收到任何错误。我看到的是

14:52:40  [INFO] Executing tasks
14:52:40  [DEBUG] getProperty(ns=null, name=ant.reuse.loader, user=false)
14:52:40  [antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
14:52:40       [echo] Copying files from ../com.x.y.z.container.build/config...
14:52:40  fileset: Setup scanner in dir C:\Jenkins\workspace\container-build\com.x.y.z.container.build\config with patternSet{ includes: [*.properties, *.xml] excludes: [] }
14:52:40  [INFO] Executed tasks

我尝试将文件添加到源目录,使源文件比目标目录中的文件更新,甚至删除目标目录中的文件。困扰我的是,fileset 似乎没有匹配任何文件,即使路径是正确的。有没有人见过这种行为?

【问题讨论】:

    标签: java ant maven-2 jenkins


    【解决方案1】:

    来自 Ant 手册中的 PatternSet 部分:http://ant.apache.org/manual/Types/patternset.html

    请注意,虽然 include 和 excludes 属性接受由逗号或空格分隔的多个元素,但嵌套的 &lt;include&gt; 和 &lt;exclude> 元素希望它们的 name 属性包含一个模式。 p>

    您可以将脚本更改为类似

    <copy todir="./Virgo/config" overwrite="true" verbose="true">
        <fileset dir="${config.folder}">
            <include name="*.properties" />
            <include name="*.xml" />
        </fileset>
    </copy>
    

    【讨论】:

    • 嗯,这很有趣,我正打算尝试一下,但我在另一个项目中使用了我的原始语法,它工作得很好,所以我认为不是这样。但你的建议奏效了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多