【问题标题】:ant build directory not setting properlyant build 目录设置不正确
【发布时间】:2016-10-18 13:00:25
【问题描述】:

我的文件目录中有以下结构

build/
    mainfolder/
    ANTFILE_A
    subfolder1/
        ANTFILE_B
        subfolder2/
            ANTFILE_C

在主子目录中,我创建了 ANTFILE_A,其中有几个目标调用 ANTFILE_B 内部的目标。在大多数情况下,目标都有效,除了一种我似乎无法理解原因的情况。

在 ANTFILE_A 中我有以下内容:

<target name="clean-subfoler1" description="Cleans subdirectories">
    <ant dir="${subfolder1-dir}" antfile="antfile_b.xml" target="clean"/>
</target>

在子文件夹 1 目录中,我有一个带有干净目标的 antfile,它清理了一些其他子目录,例如 subfolder2。当我从 subfolder1 目录中调用 ant clean 目标时,一切正常,没有问题。

当我尝试从我的主文件夹中的 ANTFILE_A 调用上面显示的目标命令时,问题就出现了。

我不断收到这样的问题:

Invalid file: D:\build\mainfolder\subfolder2\antfile_c.xml 

所以发生的事情是,由于某种原因,当我从 antfile_a 调用 clean 命令时,它似乎跳过了 subfolder1 目录并从主目录中查找 subfolder2。问题是 subfolder2 嵌套在 subfolder1 下。

现在我已经测试了basedir 是否设置正确,并且对于该特定目标,它实际上正确设置为D:\build\mainfolder\subfolder1

这就是我设置子目录文件夹的方式

我希望能够让这个目标工作而无需更改子 antfile 中的任何属性。我试过查看inheritAll,但这些都不适合我。

【问题讨论】:

    标签: ant


    【解决方案1】:

    如果我收到您的问题,我相信您的 ant 可能会在您将目标称为 antfile_c.xml 之前删除您的文件

    蚂蚁文件1:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <project name="Demo" default="clean-subfoler1" basedir=".">
    
        <property name="subfolder1-dir" value="**path to subfolder1**"/>
    
        <target name="clean-subfoler1" description="Cleans subdirectories">
            <ant dir="${subfolder1-dir}" antfile="antfileB.xml" target="clean"/>
        </target>
        </project>
    

    antfile 2:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <project name="Demo" default="clean" basedir=".">
    
        <property name="subfolder2-dir" value="**path to subfolder2**"/>
    
        <target name="clean" description="Cleans subdirectories">
            <echo message="in antfileB"/>
              <echo message="delete files in subFolder2"/>
              <delete file="antfileC.xml"/>
              <echo message="delete directory subFolder2"/>
              <delete dir="${subfolder2-dir}"/>
        </target>
    
        </project>
    

    当我运行蚂蚁时:

     clean-subfoler1:
    
    clean:
         [echo] in antfileB
         [echo] delete files in subFolder2
       [delete] Deleting: **path to** /mainfolder/subfolder1/subfolder2/antfileC.xml
         [echo] delete directory subFolder2
       [delete] Deleting directory **path to**/mainfolder/subfolder1/subfolder2
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    

    为了得到你的错误,我必须先删除文件,而不是尝试定位它:

    clean-subfoler1:
    
    clean:
         [echo] in antfileB
         [echo] delete files in subFolder2
       [delete] Deleting: **path to**/mainfolder/subfolder1/subfolder2/antfileC.xml
         [echo] call the file
    
    BUILD FAILED
    **path to**/mainfolder/antfileA.xml:7: The following error occurred while executing this line:
    **path to**/mainfolder/subfolder1/antfileB.xml:11: The following error occurred while executing this line:
    java.io.FileNotFoundException: **path to**/mainfolder/subfolder1/subfolder2/antfileC.xml (No such file or directory)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 2011-06-23
      • 2011-07-30
      • 2019-11-23
      • 1970-01-01
      相关资源
      最近更新 更多