问题描述
我有一个属性文件,让说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我的应用程序,我只需要指定属性文件,并说,我的资源文件进行过滤(如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?
推荐答案
我觉得是你在找什么。这种行为就像。
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的筛选机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!