|
Ever tried to automate Pack200 creation of multiple JAR files ?
This ANT task allows you to use a <fileset> to specify the JAR files which needs to be (re)packed. That means it can process all JAR files of your project with only one task execution in your build.xml
Ok, Let's start with an example build.xml file that shows how to use it (taken from Worldscape):
<taskdef name="p200ant"
classname="de.matthiasmann.p200ant.P200AntTask"
classpath="P200Ant.jar"/>
<target name="-post-jar">
<input message="keyPass" addproperty="keypass"/>
<input message="storePass" addproperty="storepass"
defaultvalue="${keypass}"/>
<jar destfile="${dist.dir}/lwjgl-win32.jar"
basedir="" includes="lwjgl.dll"/>
<jar destfile="${dist.dir}/lwjgl-linux.jar"
basedir="" includes="liblwjgl.so"/>
<jar destfile="${dist.dir}/lwjgl-mac.jar"
basedir="" includes="liblwjgl.jnilib"/>
<fileset id="jars2pack" dir="${dist.dir}">
<include name="**/*.jar"/>
<exclude name="lwjgl-*.jar"/>
</fileset>
<p200ant repack="true">
<fileset refid="jars2pack"/>
</p200ant>
<signjar alias="MatthiasMann" keypass="${keypass}" storepass="${storepass}">
<fileset dir="${dist.dir}">
<include name="*.jar"/>
<include name="lib/*.jar"/>
</fileset>
</signjar>
<p200ant destdir="${dist.dir}">
<fileset refid="jars2pack"/>
</p200ant>
</target>
As you can see - nothing is hardcoded except the native libs for LWJGL. This allows to add JARs to the projects without the need to modify the ANT task.
Ok lets see what attributes this ANT task supports:
| Attribute |
Description |
Required |
Default |
| repack |
Set to "true" to apply repacking to the JAR files |
No |
"false" |
| pack |
Set to "true" to write a uncompressed .pack file (not for repacking) |
No |
"false" |
| gzip |
Set to "true" to write a compressed .pack.gz file (not for repacking) |
No |
"true" |
| lzma |
Set to "true" to write a compressed .pack.lzma file (not for repacking, requires JLzma 4.65 library on the class path) |
No |
"false" |
| srcfile |
Specifies a single JAR file to (re)pack |
Unless <fileset> elements are used |
Not set |
| destfile |
When repack is set to "false" this can be used to place all .pack* files into the specified directory instead of the individual source directory of the JAR |
No |
Not set |
| keepOrder |
Keep the order of the files in the .pack.gz archive |
No |
"false" |
| KeepModificationTime |
Keep the modification time of individual files from the JAR file |
No |
"false" |
| singleSegment |
To create only a single Pack200 segment |
No |
"false" |
| segmentLimit |
Set the Pack200 segment limit in bytes |
No |
1000000 |
| configFile |
Reads Pack200 properties from a properties file |
No |
Not set |
It is also possible to specify one or more <fileset> elements. In this case the srcfile attribute must not be set.
Now I think most of you are waiting for the sourcecode ?
Ok here it is: Source and
Compiled JAR (published under the BSD license)
The LZMA SDK 4.65 is required to write LZMA compressed output files. The minimum Java heap size required is 256 MB
If you want to use Pack200 on an Apache 2.0 webserver you could use the following .htaccess file:
#Options MultiViews # need only on some server, crashes at others
MultiviewsMatch Any
AddEncoding gzip .gz
AddEncoding pack200-gzip .pack.gz
AddType application/x-java-archive .jar
That's all - it will tell Apache that all files that have .jar as first extension are of the type "application/x-java-archive". And all files with the extension .gz have content-encoding of "gzip". But an extension .pack.gz has "pack200-gzip" as content encoding.
And the MultiViews options allows delegation of other files which are smaller and also satisfy the request made by the browser (Webstart in this case).
PS: There is also a command line interface to use it outside of ANT. |