繁体   English   中英

如何在Ant解压缩的文件后追加一行?

[英]How do I append a line to a file unzipped by Ant?

我有一个默认的log4j属性文件,要将特定于应用程序的配置附加到该文件中。 该文件(与其他文件一起)包含在.zip文件中。 我使用Ant解压缩zip的内容(包括log4j属性)。 我想在解压缩发生时附加行。 这可能吗?

<unzip dest="some.dest">
    <fileset refid="some.fileset" />
    <!-- Append a line to 'log4j.properties` file -->
</unzip>

也许解决方案只是在解压缩后回显。

您可以将Ant的“ echo”任务与“ append”标志一起使用:

<echo file="log4j.properties" append="true">${line.separator}</echo>

在此处回显任务文档以供进一步参考:

http://ant.apache.org/manual/Tasks/echo.html

无需解压缩整个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>

否则,如果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.

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