ANT’s best practices - VII
12 May 2008It is common to use Ant to create WAR, JAR, ZIP, and EAR files. These files generally require a particular internal directory structure. Its normal that the archive files directory structure won’t match directory structure of your source code and build environment.
A common practice is to write an Ant target that copies a bunch of files to a temporary holding area using the desired directory structure, and then create the archive from there. This approach will work but its not that efficient.
A better approach is to use a zipfileset. This allows you to select files from any location and place them in the archive file using a different directory structure. Here is a small example:
<ear earfile="${dir.dist.server}/payroll.ear" appxml="${dir.resources}/application.xml"> <fileset dir="${dir.build}" includes="commonServer.jar"/> <fileset dir="${dir.build}"> <include name="payroll-ejb.jar"/> </fileset> <zipfileset dir="${dir.build}" prefix="lib"> <include name="hr.jar"/> <include name="billing.jar"/> </zipfileset> <fileset dir="."> <include name="lib/jdom.jar"/> <include name="lib/log4j.jar"/> <include name="lib/ojdbc14.jar"/> </fileset> <zipfileset dir="${dir.generated.src}" prefix="META-INF"> <include name="jboss-app.xml"/> </zipfileset> </ear>
Review the code above. A JAR files are placed in the lib directory of the EAR. The hr.jar and billing.jar files are copied from our build directory, therefore we use zipfileset to move them to the lib directory inside of the EAR. The prefix attribute specifies the destination directory in the EAR.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: ANT's best practices - VII