![]()
|
Ant EJB Tasks User Manualby
Version 1.5.1 Table of ContentsIntroductionAnt provides a number of optional tasks for developing Enterprise Java Beans (EJBs). In general these tasks are specific to the particular vendor's EJB Server. At present the tasks support:
EJB Tasks
ddcreatorDescription:ddcreator will compile a set of Weblogic text-based deployment descriptors into a serialized EJB deployment descriptor. The selection of which of the text-based descriptors are to be compiled is based on the standard Ant include and exclude selection mechanisms. Parameters:
Examples<ddcreator descriptors="${dd.dir}" dest="${gen.classes}" classpath="${descriptorbuild.classpath}"> <include name="*.txt"/> </ddcreator> ejbcDescription:The ejbc task will run Weblogic's ejbc tool. This tool will take a serialized deployment descriptor, examine the various EJB interfaces and bean classes and then generate the required support classes necessary to deploy the bean in a Weblogic EJB container. This will include the RMI stubs and skeletons as well as the classes which implement the bean's home and remote interfaces.
The ant task which runs this tool is able to compile several beans in a single operation. The beans to be
compiled are selected by including their serialized deployment descriptors. The standard ant
Each descriptor is examined to determine whether the generated classes are out of date and need to be regenerated. The deployment descriptor is de-serialized to discover the home, remote and implementation classes. The corresponding source files are determined and checked to see their modification times. These times and the modification time of the serialized descriptor itself are compared with the modification time of the generated classes. If the generated classes are not present or are out of date, the ejbc tool is run to generate new versions. Parameters:
Examples<ejbc descriptors="${gen.classes}" src="${src.dir}" dest="${gen.classes}" manifest="${build.manifest}" classpath="${descriptorbuild.classpath}"> <include name="*.ser"/> </ejbc> iplanet-ejbcDescription:Task to compile EJB stubs and skeletons for the iPlanet Application Server 6.0. Given a standard EJB 1.1 XML descriptor as well as an iAS-specific EJB descriptor, this task will generate the stubs and skeletons required to deploy the EJB to iAS. Since the XML descriptors can include multiple EJBs, this is a convenient way of specifying many EJBs in a single Ant task.For each EJB specified, the task will locate the three classes that comprise the EJB in the destination directory. If these class files cannot be located in the destination directory, the task will fail. The task will also attempt to locate the EJB stubs and skeletons in this directory. If found, the timestamps on the stubs and skeletons will be checked to ensure they are up to date. Only if these files cannot be found or if they are out of date will the iAS ejbc utility be called to generate new stubs and skeletons. Parameters:
Examplesdest="${build.classesdir}" classpath="${ias.ejbc.cpath}"/> dest="${build.classesdir}" keepgenerated="yes" debug="yes" iashome="${ias.home}"> <classpath> <pathelement path="."/> <pathelement path="${build.classpath}"/> </classpath> </iplanet-ejbc>wlrunDescription:The Parameters:
Nested ElementsThe wlrun task supports nested <classpath> and <wlclasspath> elements to set the repsective classpaths. ExamplesThis example shows the use of wlrun to run a server under Weblogic 5.1 <wlrun taskname="myserver" classpath="${weblogic.boot.classpath}" wlclasspath="${weblogic.classes}:${code.jars}" name="myserver" home="${weblogic.home}" properties="myserver/myserver.properties"/> This example shows wlrun being used to run the petstore server under Weblogic 6.0 <wlrun taskname="petstore" classpath="${weblogic.classes}" name="petstoreServer" domain="petstore" home="${weblogic.home}" password="petstorePassword" beahome="${bea.home}"/> wlstopDescription:The This task works for most version of Weblogic, including 6.0. You need to specify the BEA Home to have this task work correctly under 6.0 Parameters:
Nested ElementThe classpath of the wlstop task can be set by a <classpath> nested element. ExamplesThis example show the shutdown for a Weblogic 6.0 server <wlstop classpath="${weblogic.classes}" user="system" url="t3://localhost:7001" password="foobar" beahome="${bea.home}"/> ejbjarDescription:This task is designed to support building of EJB1.1 jar files. Support is currently provided for 'vanilla' EJB1.1 jar files - i.e. those containing only the user generated class files and the standard deployment descriptor. Nested elements provide support for vendor specific deployment tools. These currently include:
The task works as a directory scanning task, and performs an action for each deployment descriptor found. As such the includes and excludes should be set to ensure that all desired EJB1.1 descriptors are found, but no application server descriptors are found. For each descriptor found, ejbjar will parse the deployment descriptor to determine the necessary class files which implement the bean. These files are assembled along with the deployment descriptors into a well formed EJB jar file. Any support files which need to be included in the generated jar can be added with the <support> nested element. For each class included in the jar, ejbjar will scan for any super classes or super interfaces. These will be added to the generated jar. If no nested vendor-specific deployment elements are present, the task will simply generate a generic EJB jar. Such jars are typically used as the input to vendor-specific deployment tools. For each nested deployment element, a vendor specific deployment tool is run to generate a jar file ready for deployment in that vendor's EJB container. The jar files are only built if they are out of date. Each deployment tool element will examine its target jar file and determine if it is out of date with respect to the class files and deployment descriptors that make up the bean. If any of these files are newer than the jar file the jar will be rebuilt otherwise a message is logged that the jar file is up to date. The task uses the jakarta-BCEL framework to extract all dependent classes. This means that, in addition to the classes that are mentioned in the deployment descriptor, any classes that these depend on are also automatically included in the jar file. Naming ConventionEjbjar handles the processing of multiple beans, and it uses a set of naming conventions to determine the name of the generated EJB jars. The naming convention that is used is controlled by the "naming" attribute. It supports the following values
This is the default naming scheme. The name of the generated bean is derived from the name of the deployment descriptor. For an Account bean, for example, the deployment located using the same naming convention. The weblogic bean, for example, would be named can be separated from the code implementing the beans, which can be useful when the same bean code is deployed in separate beans. This scheme is useful when you are using one bean per EJB jar and where you may be deploying the same bean classes in different beans, with different deployment characteristics. This naming scheme uses the <ejb-name> element from the deployment descriptor to determine the bean name. In this situation, the descriptors normally use the generic names. For example, If the value of the <ejb-name> were to be given in the deployment descriptor as follows: <ejb-jar> <enterprise-beans> <entity> <ejb-name>Sample</ejb-name> <home>org.apache.ant.ejbsample.SampleHome</home>then the name of the generated bean would be Sample.jar
This scheme is useful where you want to use the standard deployment descriptor names, which may be more compatible with other EJB tools. This scheme must have one bean per jar.
In this mode, the name of the generated bean jar is derived from the directory
containing the deployment descriptors. Again the deployment descriptors typically use
the standard filenames. For example, if the path to the deployment descriptor is
This scheme is also useful when you want to use standard style descriptor names. It is often most useful when the descriptors are located in the same directory as the bean source code, although that is not mandatory. This scheme can handle multiple beans per jar. The final scheme supported by the <ejbjar> task is used when you want to specify the generated bean jar name directly. In this case the name of the generated jar is specified by the "basejarname" attribute. Since all generated beans will have the same name, this task should be only used when each descriptor is in its own directory. This scheme is most appropriate when you are using multiple beans per jar and only process a single deployment descriptor. You typically want to specify the name of the jar and not derive it from the beans in the jar. DependenciesIn addition to the bean classes, ejbjar is able to ad additional classes to the generated ejbjar. These classes are typically the support classes which are used by the bean's classes or as parameters to the bean's methods. In versions of Ant prior to 1.5, ejbjar used reflection and attempted to add the super classes and super interfaces of the bean classes. For this technique to work the bean classes had to be loaded into Ant's JVM. This was not always possible due to class dependencies. The ejbjar task in Ant releases 1.5 and later uses the jakarta-BCEL library to analyze the bean's class files directly, rather than loading them into the JVM. This also allows ejbjar to add all of the required support classes for a bean and not just super classes. In Ant 1.5, a new attribute,
The Parameters:
Nested ElementsIn addition to the vendor specific nested elements, the ejbjar task provides three nested elements. ClasspathThe <classpath> nested element allows the classpath to be set. It is useful when setting the classpath from a reference path. In all other respects the behaviour is the same as the classpath attribute. dtdThe <dtd> element is used to specify the local location of DTDs to be used when parsing the EJB deployment descriptor. Using a local DTD is much faster than loading the DTD across the net. If you are running ejbjar behind a firewall you may not even be able to access the remote DTD. The supported vendor-specific nested elements know the location of the required DTDs within the vendor class hierarchy and, in general, this means <dtd> elements are not required. It does mean, however, that the vendor's class hierarchy must be available in the classpath when Ant is started. If your want to run Ant without requiring the vendor classes in the classpath, you would need to use a <dtd> element.
supportThe <support> nested element is used to supply additional classes (files) to be included in the generated jars. The <support> element is a FileSet, so it can either reference a fileset declared elsewhere or it can be defined in-place with the appropriate <include> and <exclude> nested elements. The files in the support fileset are added into the generated EJB jar in the same relative location as their location within the support fileset. Note that when ejbjar generates more than one jar file, the support files are added to each one. Vendor-specific deployment elementsEach vendor-specific nested element controls the generation of a deployable jar specific to that vendor's EJB container. The parameters for each supported deployment element are detailed here.Jboss elementThe jboss element searches for the JBoss specific deployment descriptors and adds them (for container manager persistence only). The JBoss server uses hot deployment and does not require compilation of additional stubs and skeletons.
Weblogic elementThe weblogic element is used to control the weblogic.ejbc compiler for generating weblogic EJB jars. Prior to Ant 1.3, the method of locating CMP descriptors was to use the ejbjar naming convention. So if your ejb-jar was descriptor had to be set to the standard name META-INF/weblogic-cmp-rdbms- jar. There are a few problems with this scheme. It does not allow for more than one CMP descriptor to be defined in a jar and it is not compatible with the deployment descriptors generated by some tools. In Ant 1.3, ejbjar parses the weblogic deployment descriptor to discover the CMP descriptors, which are then included automatically. This behaviour is controlled by the newCMP attribute. Note that if you move to the new method of determining CMP descriptors, you will need to update your weblogic deployment descriptor's <type-storage> element. In the above example, you would
The weblogic nested element supports three nested elements. The first two, <classpath> and <wlclasspath>, are used to set the respective classpaths. These nested elements are useful when setting up class paths using reference Ids. The last, <sysproperty>, allows Java system properties to be set during the compiler run. This turns out to be necessary for supporting CMP EJB compilation in all environments. TOPLink for Weblogic elementDeprecated The toplink element is no longer required. Toplink beans can now be built with the standard weblogic element, as long as the newCMP attribute is set to "true" The TopLink element is used to handle beans which use Toplink for the CMP operations. It is derived from the standard weblogic element so it supports the same set of attributes plus these additional attributes
ExamplesThis example shows ejbjar being used to generate deployment jars using a Weblogic EJB container. This example requires the naming standard to be used for the deployment descriptors. Using this format will create a ejb jar file for directory. <ejbjar srcdir="${build.classes}" descriptordir="${descriptor.dir}"> <weblogic destdir="${deploymentjars.dir}" classpath="${descriptorbuild.classpath}"/> </ejbjar> If weblogic is not in the Ant classpath, the following example shows how to specify the location of the weblogic DTDs. This example also show the use of a nested classpath element. <ejbjar descriptordir="${src.dir}" srcdir="${build.classes}"> <weblogic destdir="${deployment.webshop.dir}" keepgeneric="true" args="-g -keepgenerated ${ejbc.compiler}" suffix=".jar" oldCMP="false"> <classpath> <pathelement path="${descriptorbuild.classpath}"/> </classpath> </weblogic> <dtd publicId="-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" <dtd publicId="-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN" </ejbjar> This example shows ejbjar being used to generate a single deployment jar using a Weblogic EJB container. This example does not require the deployment descriptors to use the naming standard. This will create only one ejb jar file - 'TheEJBJar.jar'. <ejbjar srcdir="${build.classes}" descriptordir="${descriptor.dir}" basejarname="TheEJBJar"> <weblogic destdir="${deploymentjars.dir}" classpath="${descriptorbuild.classpath}"/> </ejbjar> This example shows ejbjar being used to generate deployment jars for a TOPLink-enabled entity bean using a Weblogic EJB container. This example does not require the deployment descriptors to use the naming standard. This will create only one TOPLink-enabled ejb jar file - 'Address.jar'. <ejbjar srcdir="${build.dir}" destdir="${solant.ejb.dir}" descriptordir="${descriptor.dir}" basejarname="Address"> <weblogictoplink destdir="${solant.ejb.dir}" classpath="${java.class.path}" keepgeneric="false" toplinkdtd="file:///dtdfiles/toplink-cmp_2_5_1.dtd" suffix=".jar"/> </ejbjar> This final example shows how you would set-up ejbjar under Weblogic 6.0. It also shows the use of the <support> element to add support files <ejbjar descriptordir="${dd.dir}" srcdir="${build.classes.server}"> <support dir="${build.classes.server}"> <include name="**/*.class"/> </support> <weblogic destdir="${deployment.dir}" keepgeneric="true" suffix=".jar" rebuild="false"> <classpath> <pathelement path="${build.classes.server}"/> </classpath> <wlclasspath> <pathelement path="${weblogic.classes}"/> </wlclasspath> </weblogic> </ejbjar> WebSphere elementThe websphere element searches for the websphere specific deployment descriptors and adds them to the final ejb jar file. Websphere has two specific descriptors for session beans:
deployment .
This step can be performed by the websphere element as part of the jar generation process. If the
switch ejbdeploy is on, the ejbdeploy tool from the websphere toolset is called for
every ejb-jar. Unfortunately, this step only works, if you use the ibm jdk. Otherwise, the rmic
(called by ejbdeploy) throws a ClassFormatError. Be sure to switch ejbdeploy off, if run ant with
sun jdk.
For the websphere element to work, you have to provide a complete classpath, that contains all classes, that are required to reflect the bean classes. For ejbdeploy to work, you must also provide the classpath of the ejbdeploy tool and set the websphere.home property (look at the examples below).
This example shows ejbjar being used to generate deployment jars for all deployment descriptors in the descriptor dir: <property name="webpshere.home" value="${was4.home}"/> <ejbjar srcdir="${build.class}" descriptordir="etc/ejb"> <websphere dbvendor="DB2UDBOS390_V6" ejbdeploy="true" oldCMP="false" tempdir="/tmp" destdir="${dist.server}"> <wasclasspath> <pathelement location="${was4.home}/deploytool/itp/plugins/org.eclipse.core.boot/boot.jar"/> <pathelement location="${was4.home}/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime/batch.jar"/> <pathelement location="${was4.home}/lib/xerces.jar"/> <pathelement location="${was4.home}/lib/ivjejb35.jar"/> <pathelement location="${was4.home}/lib/j2ee.jar"/> <pathelement location="${was4.home}/lib/vaprt.jar"/> </wasclasspath> <classpath> <path refid="build.classpath"/> </classpath> </websphere> <dtd publicId="-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" location="${lib}/dtd/ejb-jar_1_1.dtd"/> </ejbjar> iPlanet Application Server (iAS) elementThe <iplanet< nested element is used to build iAS-specific stubs and skeletons and construct a JAR file which may be deployed to the iPlanet Application Server 6.0. The build process will always determine if the EJB stubs/skeletons and the EJB-JAR file are up to date, and it will do the minimum amount of work required.Like the WebLogic element, a naming convention for the EJB descriptors is most commonly used to specify the name for the completed JAR file. the descriptor directory, the iplanet element will search for an iAS-specific the task will fail) and a JAR file named ejb/Account.jar will be written in the destination directory. Note that when the EJB descriptors Of course, this naming behaviour can be modified by specifying attributes in the ejbjar task (for example, basejarname, basenameterminator, and flatdestdir) as well as the iplanet element (for example, suffix). Refer to the appropriate documentation for more details. Parameters:
As noted above, the iplanet element supports additional <classpath> nested elements. ExamplesThis example demonstrates the typical use of the <iplanet> nested element. It will name each EJB-JAR using the "basename" prepended to each standard is processed, the EJB-JAR will be named "Account.jar"<ejbjar srcdir="${build.classesdir}" descriptordir="${src}"> <iplanet destdir="${assemble.ejbjar}" classpath="${ias.ejbc.cpath}"/> </ejbjar>This example demonstrates the use of a nested classpath element as well as some of the other optional attributes. <ejbjar srcdir="${build.classesdir}" descriptordir="${src}"> <iplanet destdir="${assemble.ejbjar}" iashome="${ias.home}" debug="yes" keepgenerated="yes"> <classpath> <pathelement path="."/> <pathelement path="${build.classpath}"/> </classpath> </iplanet> </ejbjar>This example demonstrates the use of basejarname attribute. In this case, the completed EJB-JAR will be named "HelloWorld.jar" If multiple EJB descriptors might be found, care must be taken to ensure that the completed JAR files don't overwrite each other. <ejbjar srcdir="${build.classesdir}" descriptordir="${src}" basejarname="HelloWorld"> <iplanet destdir="${assemble.ejbjar}" classpath="${ias.ejbc.cpath}"/> </ejbjar>This example demonstrates the use of the dtd nested element. If the local copies of the DTDs are included in the classpath, they will be automatically referenced without the nested elements. In iAS 6.0 SP2, these local DTDs are found in the [iAS-install-directory]/APPS directory. In iAS 6.0 SP3, these local DTDs are found in the [iAS-install-directory]/dtd directory. <ejbjar srcdir="${build.classesdir}" descriptordir="${src}"> <iplanet destdir="${assemble.ejbjar}"> classpath="${ias.ejbc.cpath}"/> <dtd publicId="-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" location="${ias.home}/APPS/ejb-jar_1_1.dtd"/> <dtd publicId="-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN" location="${ias.home}/APPS/IASEjb_jar_1_0.dtd"/> </ejbjar> JOnAS (Java Open Application Server) elementThe <jonas> nested element is used to build JOnAS-specific stubs and
skeletons thanks to the Like the WebLogic element, a naming convention for the EJB descriptors is
most commonly used to specify the name for the completed JAR file. For example,
descriptor directory, the <jonas> element will search for a JOnAS-specific
file named Note that when the EJB descriptors are added to the JAR file, they are Of course, this naming behavior can be modified by specifying attributes in the ejbjar task (for example, basejarname, basenameterminator, and flatdestdir) as well as the iplanet element (for example, suffix). Refer to the appropriate documentation for more details. Parameters:
As noted above, the jonas element supports additional <classpath> nested elements. ExamplesThis example shows ejbjar being used to generate deployment jars using a JOnAS EJB container. This example requires the naming standard to be used for the deployment descriptors. Using this format will create a EJB JAR file for directory. <ejbjar srcdir="${build.classes}" descriptordir="${descriptor.dir}"> <jonas destdir="${deploymentjars.dir}" jonasroot="${jonas.root}" orb="RMI"/> <support dir="${build.classes}"> <include name="**/*.class"/> </support> </ejbjar> This example shows ejbjar being used to generate a single deployment jar using a JOnAS EJB container. This example does require the deployment descriptors to use the naming standard. This will create only one ejb jar file - 'TheEJBJar.jar'. <ejbjar srcdir="${build.classes}" descriptordir="${descriptor.dir}" basejarname="TheEJBJar"> <jonas destdir="${deploymentjars.dir}" jonasroot="${jonas.root}" suffix=".jar" classpath="${descriptorbuild.classpath}"/> </ejbjar> Copyright © 2000-2002 Apache Software Foundation. All rights Reserved. |