Section 8.8. Deploying to EJB Containers


8.8. Deploying to EJB Containers

Fundamentally, 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 Files

The 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 ear task is an extension of the Jar task with special treatment for application.xml. You can perform the same operation by using the prefix and fullpath attributes of zipfilesets in a zip or jar task.


Table 8-6. The ear task's attributes

Attribute

Description

Required

Default

appxml

Specifies the deployment descriptor you want to use, such as application.xml.

Yes, unless update is set to TRue.

 

basedir

Specifies the directory from which to get the files.

No

 

compress

Indicates you want to not only store data but compress it.

No

true

defaultexcludes

Specifies if you want to use default excludes or not. Set to yes/no.

No

Default excludes are used.

destfile

Specifies the EAR file you want to create.

Yes

 

duplicate

Specifies what to do if a duplicate file is found. Valid values are add, preserve, and fail.

No

add

encoding

Specifies the character encoding to use for filenames in the EAR file.

No

UTF8

excludes

Specifies the patterns matching files to exclude, as a comma- or space-separated list.

No

 

excludesfile

Specifies the name of a file where each line is a pattern matching files to exclude.

No

 

filesonly

Specifies you want to store only file entries.

No

false

includes

Specifies the patterns matching files to include, as a comma- or space-separated list.

No

 

includesfile

Specifies the name of a file where each line is a pattern matching files to include.

No

 

keepcompression

Preserves the compression as it has been in archives you're compressing instead of using the compress attribute. Available since Ant 1.6.

No

 

manifest

Specifies the manifest file to use in the compressed file.

No

 

update

Specifies whether you want to update or overwrite the target file if it exists.

No

false


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 Deployment

The 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".

You'll need vendor-specific deployment software to make this one work. Ant provides the build-end, but your server will need to provide a deployment facility that Ant can connect and interact with.


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.

Table 8-7. The serverdeploy task's attributes

Attribute

Description

Required

action

Specifies the action you want to perform, such as deploy, delete, list, undeploy, or update.

Yes

source

Specifies the path and filename of the component you want to deploy. This may be an .ear, .jar, .war, or other file type supported by the server.

Depends on the server.


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 element

This 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.

Table 8-8. The generic element's attributes

Attribute

Description

Required

classname

Specifies the classname of the deployment tool you want to run.

Yes

classpath

Specifies the classpath you want the JVM running the tool to use. May be supplied as a nested element.

Depends on the server.

password

Specifies the password you want to use on the server.

Depends on the server.

server

Specifies the URL of the server to use.

Depends on the server.

username

Specifies the username to log in with.

Depends on the server.


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 element

The 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.

Table 8-9. The weblogic element's attributes

Attribute

Description

Required

Default

application

Specifies the name of the application you want to deploy.

Yes

 

classpath

Specifies the classname of the deployment tool you want to run.

No

 

component

Specifies the string for deployment targets, of the form: <component>:<target1>,<target2>..... In this case, component is the archive name (without a file extension).

No

 

debug

Specifies if you want debug information to be displayed during deployment.

No

 

password

Specifies the password you want to use on the server.

Yes

 

server

Specifies the URL of the server to use.

No

 

username

Specifies the username to log in with.

No

system


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 element

The 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.

Table 8-10. The jonas element's attributes

Attribute

Description

Required

Default

jonasroot

Specifies the root directory for the server.

Yes

 

orb

Specifies the orb, such as RMI, JEREMIE, DAVID, and so on. If the orb is DAVID (RMI/IIOP), specifies the davidhost and davidport attributes.

No

The ORB present in the classpath.

davidhost

Specifies the value for the property david.CosNaming.default_host.

No

 

davidport

Specifies the value for the property david.CosNaming.default_port.

No

 

classname

Specifies the classname of the deployment tool you want to run.

No

org.objectweb.jonas.adm.JonasAdmin

classpath

Specifies the classpath you want the JVM running the tool to use. May be supplied as a nested element.

No

 

server

Specifies the URL of the server to use.

Yes

 


If you want to build in delay times to take into account delays in getting responses from a server, use the Ant waitfor task. You can use the sleep task for this purpose.


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>



    Ant. The Definitive Guide
    Ant: The Definitive Guide, 2nd Edition
    ISBN: 0596006098
    EAN: 2147483647
    Year: 2003
    Pages: 115
    Authors: Steve Holzner

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net