JaVa
   

Configure Ant

The Ant build tool is designed to work with targets, tasks, and subtasks. In order for Ant to know about a task, it has be defined within a <taskdef> tag. For example, if we wanted to use the ejbdoclet task in our project, we would have the following <taskdef>:

<taskdef 
 classname="xdoclet. modules. ejb.EjbDocletTask" classpathref="xdoclet. lib. path"
/>


This <taskdef> begins with the name of the task defined as ejbdoclet. This is a standard naming convention but it can be changed as needed. The name of the task is followed by the classname defining the exact class that will execute the task, and classpathref defines where the class can be found. Since XDoclet is a tool that can generate a varied number of outputs, there can be more than one <taskdef> tag in an Ant build.xml file. For example, we might need to generate code for both EJBs as well as WEB constructs, so our build.xml file would include the following code:

<taskdef classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="xdoclet.lib.path"
/>
<taskdef classname="xdoclet.modules.web.WebDocletTask" classpathref="xdoclet. lib.path"
/>


As you begin to use Ant, it becomes clear that some task definitions need to be part of a single target in order to handle dependencies between tasks. In this case, we might wrap our tasks, like this:

<target >
 <taskdef classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="xdoclet. lib.path"
 />
 <taskdef classname="xdoclet.modules.web.WebDocletTask" classpathref="xdoclet.lib.path"
 />
</target>


If you don't want to create a specific <target> element for the task definitions, they can be placed in the <init> target found in most Ant build scripts. With our defined tasks and target, we can look at building a specific <target> element for the code we need to process with XDoclet. For this example, let's assume we have a directory called \ejbsrc, which currently contains some source input files, and a destination directory called \ejbcode. We will be using XDoclet to handle some ejb tags within the input files. Our Ant <target> element would look like the following:

<target depends="xdoclet">
<ejbdoclet destdir="ejbcode"> <fileset dir="ejbsrc">
<include name="* */*Bean.java"/> </fileset>
<deploymentdescriptor destdir="deployment"/>
<homeinterface /> <localinterface /> <localhomeinterface />
</ejbdoclet>
</target>


As you can see from this target, we define the destination directory for our resulting source code as well as the location of the fileset to process. A specific deployment descriptor directory is also defined. Finally, the EJB subtasks are listed to process our implementation file.


JaVa
   
Comments