在我的文件目录
中有以下结构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 target时,一切正常,没有问题。
当我尝试从主文件夹中的ANTFILE_A调用上面显示的目标命令时,问题就出现了。
我一直收到和发出这样的问题:
Invalid file: D:buildmainfoldersubfolder2antfile_c.xml
所以发生的事情是,由于某种原因,当我从antfile_a调用clean命令时,它似乎跳过了subfolder1目录,并从主目录中查找subfolder2。问题是subfolder2嵌套在subfolder1之下。
现在我已经测试了basedir
是否设置正确,并且对于特定目标,它实际上正确地设置为D:buildmainfoldersubfolder1
。
这是我如何设置子目录文件夹
我希望能够得到这个目标的工作,而不必改变子文件中的任何属性。我试着看了一下inheritAll,但都不适合我。
如果我明白你的问题,我相信你的ant可能在你调用目标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>
当我运行ant时:
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)