模拟使用Ant的Maven2的筛选机制 [英] Simulating the Maven2 filter mechanism using Ant

查看:116
本文介绍了模拟使用Ant的Maven2的筛选机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性文件,让说my-file.properties。
除此之外,我有我的应用程序的配置文件,其中有些信息必须对my-file.properties文件的内容来填补。

I have a properties file, let say my-file.properties. In addition to that, I have several configuration files for my application where some information must be filled regarding the content of my-file.properties file.

my-file.properties:

my-file.properties:

application.version=1.0
application.build=42
user.name=foo
user.password=bar

因此​​,在我的配置文件,我会找一些 $ {application.version} $ {user.name} 将由在属性决定了他们的价值被替换的文件...

Thus, in my configuration files, I will find some ${application.version}, ${user.name} that will be replaced by their value taken in the properties file...

在我建立使用的Maven2我的应用程序,我只需要指定属性文件,并说,我的资源文件进行过滤(如<一个href=\"http://stackoverflow.com/questions/1231561/how-to-share-common-properties-among-several-maven-projects/1231594#1231594\">this回答另一个问题)。但是,我需要通过仅使用Ant来实现同样的事情。

When I build my application using Maven2, I only need to specify the properties file and say that my resources files are filtered (as in this answer to another problem). However, I need to achieve the same thing by using only Ant.

我见过蚂蚁提供过滤任务。然而,它迫使我使用该模式 @ property.key @ (即 @ user.name @ 而不是#{user.name} )在我的配置文件,这是不能接受的我的情况。

I've seen that Ant offers a filter task. However, it forces me to use the pattern @property.key@ (i.e. @user.name@ instead of #{user.name}) in my configuration files, which is not acceptable in my case.

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

How can I solve my problem?

推荐答案

我觉得 expandproperties 是你在找什么。这种行为就像的Maven2的资源过滤器


I think expandproperties is what you are looking for. This acts just like Maven2's resource filters.


举例来说,如果你有的src 目录(许多文件中的一个):

For instance, if you have src directory (one of many files):

<link href="${css.files.remote}/css1.css"/>

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

的build.xml


build.xml


*当你运行的 ExpandPropertiesTest 目标,你会在你的过滤目录以下内容:*

*When you run the ExpandPropertiesTest target you will have the following in your filtered directory: *

    <link href="/css/theCSSFiles/css1.css"/>

过滤/ test.txt的

这篇关于模拟使用Ant的Maven2的筛选机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆