ant build目录未正确设置

时间:2016-10-18 13:00:25

标签: ant

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

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目录中,我有一个带有干净目标的ant文件,它清理了一些其他子目录,如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实际上是正确的。

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

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

1 个答案:

答案 0 :(得分:1)

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

ant文件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)