ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Pringle <>
Subject kind of a "templating" solution
Date Mon, 26 Feb 2001 23:58:52 GMT
Hi all,

Like many others here, I've been struggling with how to "templatize" some
almost identical tasks, in this case building EJBs.  The ejbjar task is a
great start, and (now) works well for me to create a single bean.  However,
the limitations of the <support> element (gets added to all generated EJB
jar files) prevented me from taking advantage of the directory scanning
nature of the task.  Since our EJBs are each in a separate package, and the
packages contain all "enclosed" support classes, I came up with the
following solutions and thought I'd share with the list.  Note that this
depends on some naming conventions (the package name and jarfile name are
the same).

(short version: if an <antcallon> task would work for you then keep reading.
Think <antcall> meets <execon>, where a fileset can be passed as the value
of a single parameter.  Current version if very rough - doesn't support
multiple params, for example.  Thanks to Guillaume Binet for the initial version of this taskdef
(search on the dev list for antcallon))

Example dir structure:

/project/com/foo/ejbs/barEJB/<various classes for this EJB, including
ejb-jar.xml and weblogic-ejb-jar.xml>
/project/com/foo/ejbs/bazEJB/<various classes for this EJB, including
ejb-jar.xml and weblogic-ejb-jar.xml>

First approach (works without extending Ant with custom task):

  <!-- ===================================================================
  <!-- Create the EJB jar file for a generic EJB
  <!-- ===================================================================
  <target name="buildEJB"
      description="creates an EJB jar file"

     <!-- Clear any old deployment descriptors hanging around -->
        <fileset dir="${build.dest}/META-INF" includes="*.xml"/>

     <echo message="Building ${ejb-name}....."/>

     <ejbjar srcdir="${build.dest}"
           <path refid="project.class.path"/>
           <pathelement location="${build.dest}"/>
         <include name="**/ejb-jar.xml"/>
         <exclude name="**/*weblogic*.xml"/>
         <support dir="${build.dest}">
             <include name="com/foo/ejbs/${ejb-name}/*.class"/>
         <weblogic destdir="${deploy.dir}/ejbs"
                   compiler="jikes "
               <path refid="project.class.path"/>
               <pathelement location="${build.dest}"/>

To create a single bean, run Ant like so:
    >ant -Dejb-name="barEJB" buildEJB

This was fine and good, but for 20+ EJBs that only differed by the package
name (as far as Ant was concerned) I really didn't want to create 20+
targets that just did an <antcall> task.  So I resorted to a windows batch
file that did this:

FOR /D %%i IN (%ejbpath%\*.*) do CALL %FILES%\build.bat -Dejb-name=%%~ni

This was also find and good, but now I was annoyed that I kept restarting
ant every time - what a time waster!  With a little searching on the dev
mailing list, I found someone had submitted a proposal for an "AntCallOn"
task - hey that looked good!  With a couple of tweaks (basically so the
filesets behaved as normal the names were relative to the fileset's basedir)
I can now do this:

  <!-- ===================================================================
  <!-- build all EJBs via the AntCallOn task
  <!-- ===================================================================
  <target name="allEJBs" depends="init">
     <antcallon target="buildEJB" parameter="ejb-name" type="dir">
        <fileset dir="${src.dir}/com/foo/ejbs">
           <include name="*EJB"/>

Running it like so:
    >ant allEJBs

will do an <antcall> for each directory in the fileset.

I can post the tweaked code for the AntCallOn to the list if desired, but
didn't know how the process worked (especially since I started off of
someone else's submission).


View raw message