簡體   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