我有一个属性文件,比如说 my-file.properties。
除此之外,我的应用程序有几个配置文件,其中必须填写一些关于 my-file.properties 文件内容的信息。
我的文件。属性:
application.version=1.0
application.build=42
user.name=foo
user.password=bar
因此,在我的配置文件中,我会发现一些
${application.version}
, ${user.name}
这将被它们在属性文件中的值所取代......当我使用 Maven2 构建我的应用程序时,我只需要指定属性文件并说我的资源文件被过滤(如 this answer 到另一个问题)。但是,我需要仅使用 Ant 来实现相同的目的。
我已经看到 Ant 提供了一个 filter task .但是,它迫使我使用模式
@property.key@
(即 @user.name@
而不是 #{user.name}
)在我的配置文件中,这在我的情况下是 Not Acceptable 。我该如何解决我的问题?
最佳答案
我想 expandproperties就是你要找的。这就像 Maven2's resource filters .
输入
例如,如果您有 源 目录(许多文件之一):
<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
输出
*当您运行 时展开PropertiesTest 目标您的 中将包含以下内容已过滤 目录: *
<link href="/css/theCSSFiles/css1.css"/>
过滤/测试.txt
关于maven-2 - 使用 Ant 模拟 Maven2 过滤机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1232532/