使用Ant模拟Maven2过滤机制

Rom*_*las 5 ant maven-2 filter

我有一个属性文件,比如my-file.properties.除此之外,我的应用程序有几个配置文件,其中必须填写一些有关my-file.properties文件内容的信息.

my-file.properties:

application.version=1.0
application.build=42
user.name=foo
user.password=bar
Run Code Online (Sandbox Code Playgroud)

因此,在我的配置文件中,我会找到一些${application.version},${user.name}将替换为它们在属性文件中的值...

当我使用Maven2构建我的应用程序时,我只需要指定属性文件并说我的资源文件被过滤(如此问题的答案).但是,我需要通过仅使用Ant来实现相同的功能.

我已经看到Ant提供了一个过滤任务.但是,它迫使我在配置文件中使用模式@property.key@(即@user.name@代替#{user.name}),这在我的情况下是不可接受的.

我怎样才能解决我的问题?

lee*_*d00 20

我认为expandproperties就是你要找的东西.这就像Maven2的资源过滤器一样.


INPUT

例如,如果你有 src目录(许多文件之一):

<link href="${css.files.remote}/css1.css"/>
Run Code Online (Sandbox Code Playgroud)

SRC /的test.txt


处理

在我的ANT构建文件中,我们有:

<project default="default">
   <!-- The remote location of any CSS files -->
   <property name="css.files.remote" value="/css/theCSSFiles" />     
   ...
   <target name="ExpandPropertiesTest">

      <mkdir dir="./filtered"/>

      <copy todir="./filtered">
         <filterchain>
            <expandproperties/>
         </filterchain>     

         <fileset dir="./src" />
      </copy>
   </target>
</project>
Run Code Online (Sandbox Code Playgroud)

build.xml文件


OUTPUT

*运行ExpandPropertiesTest目标时,您的过滤目录中将包含以下内容:*

    <link href="/css/theCSSFiles/css1.css"/>
Run Code Online (Sandbox Code Playgroud)

过滤/ test.txt的