【问题标题】:Ant script to modify .java files works in "General" Eclipse project, but not in Maven Eclipse project修改 .java 文件的 Ant 脚本适用于“常规”Eclipse 项目,但不适用于 Maven Eclipse 项目
【发布时间】:2012-11-16 00:44:50
【问题描述】:

我有一个相对简单的 Ant 脚本 commentOutXmlAnnotations.xml,它可以编辑所有子目录中 Java 文件的内容,以通过正则表达式注释掉某些行:

<?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>

如果我将commentOutXmlAnnotations.xml 放到一个新的General Eclipse 项目中,子目录中有.java 文件,然后右键单击并执行“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 脚本以在其所在目录中执行?

【问题讨论】:

    标签: eclipse maven ant


    【解决方案1】:

    所以,愚蠢的错误。

    上面的脚本只搜索一个目录,所以看起来脚本没有任何影响,因为所有java文件的包名都比一个目录长。

    要搜索所有子目录多层次的深度,fileset 元素应该是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 2011-05-12
      • 2015-11-30
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2019-03-16
      相关资源
      最近更新 更多