Saturday, 2 February 2013

Ant Script: How To Pack Multiple Jars In A Single Script

As we know that, pack200 is the best compression tool to compress java classes(In my experience, it compresses one third to one ninth of its original size). Sometimes we need to pack a bundle of jar files(Especially library files), but it is hard to use command line syntax to bundle them all in a single shot. But ant will help us to automate this, even if you don't know ant , don't worry. Just follow these steps.

Steps to pack multiple jars
  • Download ant from here
  • Set %ANT_HOME% as path variable and add ant/bin to path.
  • Create a file and name it build.xml. (If you don't know any thing about build.xml, just copy following code and save it as build.xml).
<project>
<property name="dir.jar" value="
Source_Folder"/>
<apply executable="pack200" parallel="false" dest="
Destination_Folder">
        <arg value="--modification-time=latest"/>
        <arg value="--deflate-hint=true"/>
        <arg value="--segment-limit=-1"/>
        <targetfile/>
        <srcfile/>
        <fileset dir="${dir.jar}/" includes="**/*.jar" />
    <mapper type="glob" from="*" to="*.pack.gz" />
 </apply>
</project>


In the preceding code snippet, Source_Folder and Destination_Folder are user defined folders. Make sure that your jar files are in source_folder and these two folders should be in the same folder as build.xml .
  • Final step is, type ant. 
Done... Your packed jars with extenstion pack.gz will be created in Destination_Folder. 






    

No comments:

Post a Comment