Pack200Tasks

Introduction

These task provide an interface to the Java Pack200 API. The implementation follows the pack200(1) command line interface. All the functionality of the pack200(1) can be accomplished by this task. The primary advantage of using this task over calling the CLI from ANT is performance. The user is encourage to familiarize themselves with java.util.jar.pack.Pack200, before using these Tasks.

Note: JRE/JDK 1.5+ required.

The Tasks

Pack200Task
Unpack200Task

Pack200Task

Description

Packs a jar to Packed file or a compressed packed file, as well as repack a file, typically for jarsigning.


Parameters



Attribute Description Required
src
file name of the input jar to be packed, must have extension ".jar"
Yes
destfile
file name of the output file, extensions, ".pack or .pac"
Yes
gzipoutput
specifies the file should be compressed using value "true, false", cannot be used with repack, the destfile must have an extension ".pack.gz, pac.gz".
No
verbose
specify a numeric value for the verbosity values range from 0 to 9.
No
modificationtime
generic modification time for the entries with in a jar, string  "keep, latest".
No
stripdebug
strips Java Class attributes not required for runtime a value of "true, false". No
deflatehint
deflate hint for the jar entries when the packed file is unpacked, "keep, true, false"
No
keepfileorder
specifies whether the ordering of the entries should be maintained upon unpacking, string "true, false".
No
unknownattribute
action to be taken when an unknown java attribute is encountered by the packer, string "strip, error, pass" No
segmentlimit
the file sizes (numerical value) to consider for each segment in a packed files.
No
effort
the packing effort a numerical value ranging from 1 to 9.
No
configfile
used to set other options, by creating a properties file and specifying it here.
No

Either gzipout or repack must be used, but not both.

Unpack200Task

Description

Unpacks a packed stream to a jar.

Parameters

Attribute Description Required
src
file name of the input packed stream, the extension must be ".pack, pac, .gz" Yes
destfile
file name of the output JAR file, extensions, ".jar"
Yes
verbose
specify a numeric value for the verbosity values range from 0 to 9.
No

Examples

In order to use this, download the Pack200Task.jar to some location of your choice <install>/Pack200Task.jar.
In the build.xml create the Task for example:

  <!-- Create our Pack200 Tasks -->
  <target name="p200">

     <!-- Create our packer task -->
     <taskdef name="pack200"
    classname="com.sun.tools.apache.ant.pack200.Pack200Task"
    classpath="<install>/Pack200Task.jar"/>

     <!-- Create our unpacker task -->
     <taskdef name="unpack200"
    classname="com.sun.tools.apache.ant.pack200.Unpack200Task"
    classpath="${dist}/Pack200Task.jar"/>

  </target>

and you are ready to go.....

Here is a simple example to pack and unpack a jar.

  <target name="simple" depends="p200">
 <pack200 src="${test}/Test.jar"
destfile="${test}/testout.pack.gz"/>
     <unpack200 src="${test}/testout.pack.gz" 
dest="${test}/foo.jar"/>
  </target>
To repack a file for signing, the above example also accomplishes the same.
  <target name="simple2" depends="p200">
 <pack200 src="${test}/Test.jar"
destfile="${test}/testout.jar
repack="true"/>
  </target>

An example which describes the use of some attributes to reduce the resulting pack file size.
  <target name="complex" depends="p200">
      <delete file="${test}/testout.pack"/>
 <pack200 src="${test}/Test.jar"
destfile="${test}/testout.pack"
zipoutput="false"
            verbose="1"
modificationtime="latest"
deflatehint="false"
unknownattribute="error"
<unpack200 src="${test}/testout.pack"
dest="${test}/foobar.jar"/>
  </target> 

The above example using a configuration file to acheive the same result.
  <target name="complex2" depends="p200">
<!-- Create a configuration file -->
     <echo file="${test}/pack.conf" append="false">pack.modification.time=latest
pack.deflate.hint=false
pack.unknown.attribute=error
</echo>
     <pack200 src="${test}/Test.jar"
destfile="${test}/testout.pack"
configfile="${test}/pack.conf"
verbose="1"/>

<unpack200 src="${test}/testout.pack"
dest="${test}/foobar.jar"/>
  </target>




Sun Copyright ???