Ant中使用檔案的壓縮

來源:互聯網
上載者:User
<?xml version="1.0"?>

<project name="access" default="show" basedir=".">
    <buildnumber/>

    <target name="show">
        <echo message="${build.number}"/>
        <tar destfile="${build.number}.tar.bz2" compression="bzip2">
            <fileset dir=".">
                <include name="*.xml"/>
            </fileset>
        </tar>

        <untar src="${build.number}.tar.bz2" compression="bzip2" dest="dest" />
    </target>
</project>

buildnumber: 每次啟動並執行時候,ant都會將該值進行增加並寫到一個build.number文檔中(在basedir下面).當然,你也可以使用file屬性指定到某個檔案中.如下

<buildnumber file="my.properties"/>

如果在運行時,ant在指定(或者預設)的檔案中找不到build.number值,它會重建該值,並從0開始增長.

 

tar是Linux平台上的打包命令. 在Linux上,檔案壓縮命令如zip,gzip,bzip2等,都只能針對單獨的檔案進行,你不能對檔案或多個檔案進行壓縮. 為了讓多個檔案形成一個整體,就需要使用tar命令. tar會將零散的多個檔案串連成一個整體,但是預設的情況下,它是不會壓縮這些零散的檔案的。也就是說tar命令的產生就是為也形成一個整體檔案(名副其實的打包命令),然後再供gzip、bzip2之類的檔案壓縮命令使用。在tar後來的發展過程中,為了方便,tar有了一些檔案壓縮的屬性選項。ant的tar就是模仿linux上tar命令。你可以加一個compression屬性對檔案進行壓縮。具體的打包和解包如上。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.