Ant从zip文件中读取属性文件

时间:2010-12-02 15:55:54

标签: ant properties zip

在ant中有没有办法从zip文件中加载属性?

我有一个项目ant文件,需要使用zip文件中的文件中的一些属性。 zip文件存储在CI服务器上的已知位置。

/known location/file.zip
   |
   +--- properties/details.properties

以下不起作用

<project name="test" basedir="." >
    <property file="/known location/file.zip/properties/details.properties"/>
    ....
</project>

2 个答案:

答案 0 :(得分:1)

您可以将文件解压缩到临时位置,然后加载解压缩的属性文件

<target name="load-zipped-props">
    <unzip src="${propfile-name}.zip" dest="${unzip-destination}" />
    <property file="${unzip-destination}/${propfile-name}.properties"/>
</target>

答案 1 :(得分:1)

由于zip文件和jar文件基本相同,因此您可以使用url任务的property形式,并使用jar网址。

<property url="jar:file:/known location/file.zip!/properties/details.properties" />

请注意网址前面的jar:file:!/将zip文件位置与zip中属性文件的路径分开。

有关jar:网址语法的详细信息,请参阅JarURLConnection文档。

相关问题