0

commentOutXmlAnnotations.xmlすべてのサブディレクトリのJavaファイルの内容を編集して、正規表現を介して特定の行をコメント化する、比較的単純なAntスクリプトがあります。

<?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.*;
        -@Xml*

        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>

サブディレクトリに.javaファイルがある新しいGeneralEclipseプロジェクトにドロップcommentOutXmlAnnotations.xmlし、右クリックして「Run As-> Ant Build」を実行すると、すべてが正常に機能し、.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プロジェクトのディレクトリ設定と関係があると思います。

Eclipse Mavenプロジェクトで、プロジェクト/ Antスクリプトが配置されているのと同じディレクトリで実行するように構成するにはどうすればよいですか?

4

1 に答える 1

0

だから、愚かな間違い。

上記のスクリプトは1つのディレクトリのみを検索します。したがって、すべてのJavaファイルのパッケージ名が1つのディレクトリより長いため、スクリプトは影響を与えなかったようです。

複数レベルの深さのすべてのサブディレクトリを検索するには、fileset要素は次のようになります。

<fileset dir="." >
    <include name="**/*.java" />
</fileset>
于 2012-11-15T16:44:50.357 に答える