Compressing Tasks

Description

For each of the supported compression formats there is a correspondig task that compresses a resource. These tasks are not based on their core cousin tasks but provide similar functionality.

Parameters

Attribute Description Required
src the resource to compress. Yes, or a nested resource collection or a nested archiving task.
srcfile the file to compress.
dest the destination resource to create. Exactly one of the two or a nested dest element.
destfile the destination file to create.

Parameters specified as nested elements

any resource or single element resource collection

The specified resource will be used as src.

any archiving task

The task's output will be used as src.

You must not specify the archiving task's dest attribute or nested element.

any compressing task

Since Compress Antlib 1.1

The task's output will be used as src.

You must not specify the compressing task's dest attribute or nested element.

dest

Accepts any resource or single element resource collection as nested element.

The specified resource will be used as dest.

BZip2

Is a compressing task that uses the BZIP2 compression algorithm.

Deflate

Is a compressing task that uses the DEFLATE compression algorithm.

Since Compress Antlib 1.5

This task supports the following additional attributes:

Attribute Description Required
level Non-default level at which file compression should be performed. Valid values range from 0 (no compression/fastest) to 9 (maximum compression/slowest). No
zlibheader Whether to write ZLIB headers. No, defaults to true

GZip

Is a compressing task that uses the GZIP compression algorithm.

This task supports the following additional attributes:

Attribute Description Required
level Non-default level at which file compression should be performed. Valid values range from 0 (no compression/fastest) to 9 (maximum compression/slowest). Since Compress Antlib 1.5 No

LZ4

Is a compressing task that uses the LZ4 compression algorithm.

Since Compress Antlib 1.5

Parameters

In addition to the attributes supported by all compressing task this task also supports.

Attribute Description Required
framed Whether to use the frame format. No, defaults to true.

LZMA

Is a compressing task that uses the LZMA compression algorithm.

Since Compress Antlib 1.5

Pack200

Is a compressing task that uses the Pack200 compression algorithm.

The source of this task must be a valid JAR archive.

The created archive will not be compressed, use another <gzip> task to create a pack.gz archive.

Parameters

In addition to the attributes supported by all compressing task this task also supports.

Attribute Description Required
pack200strategy Apache Commons Compress' Pack200 streams cache the archive data either in memory or in a temporary file. User this attribute to control which strategy is chosen. Valid values are "in-memory" and "temp-file". No, defaults to in-memory.

Parameters specified as nested elements

In addition to the nested elements supported by all compressing task this task also supports.

property

Sets a property for the packer (see the Pack200 javadocs for details).

Attribute Description Required
key Name of the property. Yes.
value Value of the property. Yes.

Snappy

Is a compressing task that uses the Snappy compression algorithm.

Since Compress Antlib 1.5

Parameters

In addition to the attributes supported by all compressing task this task also supports.

Attribute Description Required
framed Whether to use the framing format.
When setting this to false only resources of known (uncompressed) size can be compressed (for example files).
No, defaults to true.

XZ

Is a compressing task that uses the XZ compression algorithm.

Examples

    <cmp:gzip src="test.tar" dest="test.tar.gz"
         xmlns:cmp="antlib:org.apache.ant.compress"/>
    <cmp:bzip2 src="test.tar" destfile="test.tar.bz2"
          xmlns:cmp="antlib:org.apache.ant.compress"/>
    <cmp:gzip destfile="archive.tar.gz" xmlns:cmp="antlib:org.apache.ant.compress">
      <url url="http://example.org/archive.tar"/>
    </cmp:gzip>

downloads http://example.org/archive.tar and compresses it to archive.tar.gz in the project's basedir on the fly.

    <cmp:gzip xmlns:cmp="antlib:org.apache.ant.compress">
      <cmp:tar>
        <fileset dir="src"/>
      </cmp:tar>
      <dest>
        <file file="src.tar.gz"/>
      </dest>
    </cmp:gzip>

Creates a tar archive of all files in the src directory, compresses it using GZIP and stores it in the file src.tar.gz in the project's basedir.

    <cmp:pack200 dest="foo.pack"
                 xmlns:cmp="antlib:org.apache.ant.compress"
                 src="foo.jar">
      <property key="pack.effort" value="9"/>
    </cmp:pack200>
  

Packs foo.jar trying to prepare for better compression results by using above than normal effort.

    <cmp:gzip xmlns:cmp="antlib:org.apache.ant.compress">
      <cmp:pack200>
        <file file="foo.jar"/>
      </cmp:pack200>
      <dest>
        <file file="foo.pack.gz"/>
      </dest>
    </cmp:gzip>

Creates a deflated Pack200 archive of foo.jarand stores it in the file foo.pack.gz in the project's basedir.