我有一个默认的log4j属性文件,我想将特定于应用程序的配置附加到该文件中。该文件(与其他文件一起)包含在.zip文件中。我使用Ant解压缩压缩包中的内容(包括log4j属性)。我想要在解压发生时附加这行。这个是可能的吗?
<unzip dest="some.dest">
<fileset refid="some.fileset" />
<!-- Append a line to 'log4j.properties` file -->
</unzip>也许解决方案就是在我解压后回显。
发布于 2013-01-25 00:04:12
您可以使用带有append标志的Ant "echo“任务:
<echo file="log4j.properties" append="true">${line.separator}</echo>Echo任务文档在这里进一步参考:
http://ant.apache.org/manual/Tasks/echo.html
发布于 2013-01-26 06:17:37
不需要解压缩整个zipfile,使用
如果log4j.properties驻留在压缩包的根目录中:
<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>https://stackoverflow.com/questions/14505525
复制相似问题