2016-10-18 114 views
0

我有以下的結構,我的文件目錄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目錄中。我在那清理其他一些subdirectores像subfolder2的清潔目標的antfile。當我從subfolder1目錄中調用ant clean目標時,一切正常,沒有問題。

當我嘗試從主文件夾中的ANTFILE_A調用上面顯示的目標命令時,問題就出現了。

我不斷收到像這樣的問題:

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

那麼什麼情況是,由於某種原因,當我從antfile_a它似乎跳過subfolder1目錄,並從內部尋找subfolder2調用clean命令主目錄。問題是子文件夾2嵌套在子文件夾1下。

現在我已經測試過是否被正確設置,並且它實際上正確地針對該特定目標的D:\build\mainfolder\subfolder1

這是我的子目錄文件夾

我希望能夠得到這個目標,而不必子antfiles內改變任何財產的工作。我試着看繼承,但沒有爲我工作。

回答

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)