简体   繁体   English

如何在文件中存储Apache Ant属性值

[英]How to store Apache Ant property value in file

I need to modify a (xml-)file from Apache Ant. 我需要修改Apache Ant中的(xml-)文件。 "loadfile" task allows to load the file's content in a property. “loadfile”任务允许在属性中加载文件的内容。 But how to store the property's value back to a file after its (property) modification? 但是如何在属性修改后将属性的值存储回文件?

Of course I could write custom task to perform this operation but I would like to know if there's some existing implementation. 当然我可以编写自定义任务来执行此操作,但我想知道是否有一些现有的实现。

You can use the echo task. 您可以使用echo任务。

<echo file="${fileName}" message="${xmlProperty}"/>

The echoxml task might be of interest to you as well. 您也可能对echoxml任务感兴趣。

Use propertyfile task. 使用propertyfile任务。 An example taken from ant manual: 从ant手册中取得的一个例子:

<propertyfile file="my.properties">
  <entry  key="abc" value="${abc}"/>
</propertyfile>

This may be better than echo as it updates the properties file with a given value, while echo appends to or overwrites the whole file. 这可能比echo更好,因为它使用给定值更新属性文件,而echo附加或覆盖整个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM