2012-11-15 77 views
0

我有編輯所有子目錄中的Java文件的內容相對簡單的Ant腳本commentOutXmlAnnotations.xml註釋掉通過正則表達式的某些行:Ant腳本修改.java文件中的「常規」 Eclipse項目的工作,但不是在Maven的Eclipse項目

<?xml version="1.0"?> 
<project 
    name="CommentOutXmlAnnotations" 
    basedir="." 
    default="commentOutXmlAnnotations" > 

    <!-- This Ant script comments out the following lines from the Java files in this directory 
     and all subdirectories: 
     -import javax.xml.bind.annotation.*; 
     [email protected]* 

     To run this in Eclipse, right-click on this file and click "Run As->Ant Build".    
    --> 

    <target 
     name="commentOutXmlAnnotations"   
     description="Run" > 
      <replaceregexp 
       byline="false" 
       flags="g" > 

       <regexp pattern="(@Xml[A-Za-z0-9]+(\([^)]+\))?|import javax\.xml\.bind\.annotation\.[A-Za-z0-9.]+;)[ \t]*(\r?\n)" /> 

       <substitution expression="/*\1*/\3" /> 

       <fileset dir="." > 
        <include name="*/*.java" /> 
       </fileset> 
      </replaceregexp>   
    </target> 
</project> 

如果我把commentOutXmlAnnotations.xml到一個新的通用的Eclipse項目與子目錄,然後右鍵單擊並做「運行AS-> Ant構建」 .java文件,一切工作正常,並在.java文件的行被註釋掉了。

但是,如果我放棄這一commentOutXmlAnnotations.xml文件到Eclipse的Maven項目,並嘗試做同樣的事情,它似乎執行,我會得到的控制檯輸出:

Buildfile: D:\Eclipse_Juno_SR1_OTP\opentripplanner-pojos-unversioned\commentOutXmlAnnotations.xml 
commentOutXmlAnnotations: 
BUILD SUCCESSFUL 
Total time: 302 milliseconds 

不過的內容子目錄下的.java文件不會改變。我認爲這是與Maven項目目錄設置。

如何配置項目/ ant腳本在它被放置在同一目錄下執行,在Eclipse Maven項目?

回答

0

所以,愚蠢的錯誤。

上述腳本只搜索一個目錄很深,所以它看起來像腳本沒有任何影響,因爲所有的java文件有多個目錄的軟件包名稱。

要搜索所有深子目錄多個級別,則fileset元素應該是:

<fileset dir="." > 
    <include name="**/*.java" /> 
</fileset>