|
8.8. Deploying to EJB ContainersFundamentally, deploying to Enterprise JavaBean (EJB) application servers is similar to other Ant deployment projects you've seen. You can use the tasks covered to package and deploy EJB applications. For example, you can see a build file developed for the JBoss server in Example 8-6; this build file first creates a .war file and then packages it into an .ear file for deployment. Example 8-6. A Jboss EJB build (ch08/ejb/build.xml)<?xml version="1.0" ?> <project default="main" basedir="."> <target name="main" depends="init, compile, war, ear"/> <target name="init"> <property name="src" value="${basedir}/src"/> <property name="bin" value="${basedir}/output"/> <property name="web" value="${basedir}/web"/> <property name="descriptors" value="${basedir}/output/deploymentdescriptors"/> <property name="eardir" value="${basedir}/output/ear"/> <property name="wardir" value="${basedir}/output/war"/> <property name="warfile" value="app.war"/> <property name="earfile" value="app.ear"/> <mkdir dir="${wardir}/WEB-INF"/> <mkdir dir="${wardir}/WEB-INF/classes"/> <mkdir dir="${eardir}/META-INF"/> </target> <target name="compile"> <javac destdir="${bin}" srcdir="${src}" includes="**/*.java" /> </target> <target name="war"> <copy todir="${wardir}"> <fileset dir="${web}" includes="**/*.*" /> </copy> <copy file="${descriptors}/web.xml" todir="${wardir}/WEB-INF" /> <copy todir="${wardir}/WEB-INF/classes"> <fileset dir="${bin}" includes="**/*.class" /> </copy> <jar jarfile="${eardir}/${warfile}" basedir="${wardir}" /> </target> <target name="ear"> <copy file="${descriptors}/application.xml" todir="${eardir}/META-INF" /> <jar jarfile="${basedir}/${earfile}" basedir="${eardir}" /> </target> </project> That's all it takes. Though this build file gets the job done using standard Ant tasks, tasks built into Ant make it easier to work with EJB applications, starting with the ear task. 8.8.1. Creating EAR FilesThe ear task is handy for creating .ear files and makes special provisions for the application.xml file needed in most EARs. It's not mandatory to use this task to create a .ear file, but it can make life easier. You can see the attributes of this task in Table 8-6.
The extended zipfileset element from the zip task, which supports the attributes prefix, fullpath, and src, is available in the ear task. The nested metainf element specifies a fileset; all files included in this fileset will end up in the META-INF directory of the .ear file. This task lets you specify where to get application.xml from, using the appxml attribute. Here's an example that creates an .ear file: <ear destfile="${output}/app.ear" appxml="${src}/application.xml"> <fileset dir="${wardir}" includes="*.war"/> </ear> 8.8.2. Supporting Hot DeploymentThe serverdeploy task is designed to support hot deployment (where you don't have to take the server down before deploying) to EJB-aware servers. You set the action attribute to values you've seen, like those used for the Tomcat manager servlet: "deploy", "delete", and "undeploy".
As of this writing, this task only supports Weblogic servers and the JOnAS 2.4 Open Source EJB server, but support for other EJB containers should be added soon. This task has only two attributes, which appear in Table 8-7, and requires some nested elements.
The serverdeploy task supports a nested classpath element to set the classpath. It supports the vendor-specific generic, jonas, and weblogic nested elements. 8.8.2.1 The generic elementThis is the element you use for generic Java-based deployment if you've got deployment codea Java classsupplied by the server's vendor. If there's a vendor-specific element for serverdeploy, use that, of course, but if not, try the generic element. The attributes of this element appear in Table 8-8.
The generic element supports nested arg and jvmarg elements. Here's an example using the generic element for deployment that assumes the deployment tool for the target Web server is org.steven.j2ee.config.Deploy: <serverdeploy action="deploy" source="${eardir}/app.ear"> <generic classname="org.steven.j2ee.config.Deploy" classpath="${classpath}" username="${user.name}" password="${user.password}"> <arg value="-install"/> <jvmarg value="-mx512m"/> </generic> </serverdeploy> 8.8.2.2 The weblogic elementThe weblogic element is designed to run the weblogic.deploy deployment tool; legal actions for this tool are deploy, undeploy, list, update, and delete. The attributes for this element appear in Table 8-9.
Here's an example using this element inside a serverdeploy element to deploy to a WebLogic server: <serverdeploy action="deploy" source="${eardir}/app.ear"> <weblogic application="app" server="ff19://server:7001" classpath="${weblogic.home}/lib/weblogic.jar" username="${user.name}" password="${user.password}" component="appserver,productionserver" /> </serverdeploy> 8.8.2.3 The jonas elementThe jonas element supports deployment to JOnAS (Java Open Applicaton Server) servers. Valid actions for the JOnAS deployment tool (org.objectweb.jonas.adm.JonasAdmin ) are deploy, undeploy, list and update. The attributes of this element appear in Table 8-10.
The jonas element supports nested classpath, arg, and jvmarg elements. Here's an example using serverdeploy to deploy to a JOnAS server: <serverdeploy action="deploy" source="${eardir}/app.jar"> <jonas server="JOnAS5" jonasroot="${jonas.root}"> <classpath> <pathelement path="${jonas.root}/lib/RMI_jonas.jar"/> </classpath> </jonas> </serverdeploy> |
|