Chapter 27. Ant EJB Tasks: Using EJB-JAR

The <jonas> nested element uses the GenIC tool to build JOnAS-specific stubs and skeletons and constructs a JAR file that can be deployed to the JOnAS Application Server. The build process always determines if the EJB stubs/skeletons and the EJB-JAR file are up-to-date and performs the minimum amount of work required.

A naming convention for the EJB descriptors is most commonly used to specify the name for the completed JAR file. For example, if the EJB descriptor ejb/Account-ejb-jar.xml is located in the descriptor directory, the <jonas> element searches for a JOnAS-specific EJB descriptor file named ejb/Account-jonas-ejb-jar.xml, and a JAR file named ejb/Account.jar will be written in the destination directory. The <jonas> element can also use the JOnAS naming convention. Using the same example, the EJB descriptor can also be named ejb/Account.xml (no base name terminator here) in the descriptor directory. The <jonas> element will then search for a JOnAS-specific EJB descriptor file called ejb/jonas-Account.xml. This convention does not strictly follow the EJB-JAR naming convention recommendation, but it is supported for backward compatibility with previous version of JOnAS.

Note that when the EJB descriptors are added to the JAR file, they are automatically renamed META-INF/ejb-jar.xml and META-INF/jonas-ejb-jar.xml.

Furthermore, 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).

27.1. ejbjar Parameters

AttributeDescriptionRequired
destdirThe base directory into which the generated JAR files will be written. Each JAR file is written in directories that correspond to their location within the descriptordir namespace.Yes
jonasrootThe root directory for JOnAS.Yes
jonasbaseThe base directory for JOnAS. If omitted, it defaults to jonasroot.No
classpathThe classpath used when generating EJB stubs and skeletons. If omitted, the classpath specified in the "ejbjar" parent task will be used. If specified, the classpath elements will be prefixed to the classpath specified in the parent "ejbjar" task. A nested "classpath" elements can also be used. Note that the needed JOnAS JAR files are automatically added to the classpath.No
keepgeneratedtrue if the intermediate Java source files generated by GenIC must not be deleted. If omitted, it defaults to false.No
nocompiltrue if the generated source files must not be compiled via the Java and RMI compilers. If omitted, it defaults to false.No
novalidationtrue if the XML deployment descriptors must be parsed without validation. If omitted, it defaults to false.No
javacJava compiler to use. If omitted, it defaults to the value of build.compiler property.No
javacoptsOptions to pass to the Java compiler.No
protocolsComma-separated list of protocols (chosen within jrmp, iiop, cmi) for which stubs should be generated. Default is jrmp.No
rmicoptsOptions to pass to the rmi compiler.No
verboseIndicates whether or not to use -verbose switch. If omitted, it defaults to false.No
additionalargsAdd additional args to GenIC.No
keep generictrue if the generic JAR file used as input to GenIC must be retained. If omitted, it defaults to false.No
suffixString value appended to the JAR filename when creating each JAR. If omitted, it defaults to .jar.No
nogenicIf this attribute is set to true, JOnAS's GenIC will not be run on the EJB JAR. Use this if you prefer to run GenIC at deployment time. If omitted, it defaults to false.No
mappernamesList of JORM mapper names, separated by commas, used for CMP2.0 to indicate for which mappers the container classes should be generated.No
jvmoptsAdditional args to pass to the GenIC JVM.No

As noted above, the jonas element supports additional <classpath> nested elements.

NoteNote
 

To avoid java.lang.OutOfMemoryError, you can use the element jvmopts to change the default memory usage.

27.1.1. ejbjar Example

This 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 creates a EJB JAR file for each variation of *-jar.xml that is located in the deployment descriptor directory.

<ejbjar srcdir="${build.classes}"
        descriptordir="${descriptor.dir}">
  <jonas destdir="${deploymentjars.dir}"
         jonasroot="${jonas.root}" orb="RMI"/>
  <include name="**/*.xml"/>
  <exclude name="**/jonas-*.xml"/>
  <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 creates 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" orb="${genic.org}"/>
  <include name="**/ejb-jar.xml"/>
  <exclude name="**/jonas-ejb-jar.xml"/>
</ejbjar>