[英]How do I append a line to a file unzipped by Ant?
I have a default log4j
properties file to which I want to append an application specific configuration. 我有一个默认的
log4j
属性文件,要将特定于应用程序的配置附加到该文件中。 The file is contained (with other files) within a .zip file. 该文件(与其他文件一起)包含在.zip文件中。 I use Ant to unzip the contents of the zip (including the log4j properties).
我使用Ant解压缩zip的内容(包括log4j属性)。 I want to append the line when the unzip happens.
我想在解压缩发生时附加行。 Is this possible?
这可能吗?
<unzip dest="some.dest">
<fileset refid="some.fileset" />
<!-- Append a line to 'log4j.properties` file -->
</unzip>
Maybe the solution is just to echo after I've unzipped. 也许解决方案只是在解压缩后回显。
You can use the Ant "echo" task with the "append" flag: 您可以将Ant的“ echo”任务与“ append”标志一起使用:
<echo file="log4j.properties" append="true">${line.separator}</echo>
Echo task doc here for further reference: 在此处回显任务文档以供进一步参考:
http://ant.apache.org/manual/Tasks/echo.html http://ant.apache.org/manual/Tasks/echo.html
No need to unzip the whole zipfile, use 无需解压缩整个zip文件,使用
if log4j.properties resides in rootdirectory of zip : 如果log4j.properties位于zip的根目录中:
<project>
<!-- unzip log4j.properties only -->
<unzip src="foo.zip" dest=".">
<patternset>
<include name="log4j.properties" />
</patternset>
</unzip>
<!-- put new key in or overwrite if already existing -->
<propertyfile file="log4j.properties">
<entry key="log4j.logger.com.foobar.xyz" value="ERROR" />
</propertyfile>
<!-- update zip with modified log4j.properties -->
<zip destfile="foo.zip" update="true">
<fileset dir="." includes="log4j.properties" />
</zip>
</project>
else if log4j.properties resides in any subfolder of zip : 否则,如果log4j.properties驻留在zip的任何子文件夹中:
<project>
<!-- unzip log4j.properties only -->
<unzip src="foo.zip" dest=".">
<patternset>
<include name="**/log4j.properties" />
</patternset>
</unzip>
<fileset dir="." includes="**/log4j.properties" id="foo"/>
<!-- put new key in or overwrite if already existing -->
<propertyfile file="${toString:foo}">
<entry key="log4j.logger.com.foobar.xyz" value="ERROR" />
</propertyfile>
<!-- update zip with modified log4j.properties -->
<zip destfile="foo.zip" update="true">
<fileset dir="." includes="${toString:foo}" />
</zip>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.