【发布时间】: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 脚本以在其所在目录中执行?
【问题讨论】: