我有一个默认的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>