EJB Deployment
- Create ejb-jar.xml deployment descriptor (*** possibly optional ****)
- Create any necessary vendor specific deployment descriptors
- Create Code
- Typically jar up deployment descriptors with EJB class files into a single "ejb-jar" file. Deploy by either
copying to standard "hot-deploy" directory or use deployment application
tool given by vendor
jar -cvf Whatever.jar *.class *.xml
OR
jar -cvf Whatever.jar * (where have class and xml descriptor files in directory)
- This creates the jar file Whatever.jar
- DO THIS from the directory containing class files.
|
J2EE tutorial w/ info on EJBs
Puzzle Related info:
|
Configuration file see following directory:
/opt/glassfish3/glassfish/config
|
Ear files and Directory structure
You are deploying an application called hello (hello.ear) that contains an EJB module (hello.jar). With directory-based deployment, the build scripts for your application create the source and deployment descriptors such that the built files always follow the directory structure.
- JAR = Java Application Archive. The EJB JAR file is the standard format for packaging enterprise beans. This file contains the deployment descriptors if there are any(ejb-jar.xml,sun-ejb.jar.xml), the bean classes (interface and bean) and all of the utility classes. ZIP format contains multiple class files.
- WAR= Web ARchive
Used to package all the components of a Web Application. It may contain JARs, JSPs, Servlets, HTMLs, GIFs, etc. The purpose of this archive format is same as that of the JAR - to make the deployment, shipping, and in turn the maintenance process easier. This will have an XML file named web.xml as the Deployment Descriptor.
- EAR = Enterprise Application Archive.
An enterprise application may be composed of several Web Applications and other independent JARs, like EJB JARs. This archive file format is used in those cases to bundle all the components of an enterprise application into a single file. Again the purpose is same - making deployment, shipping, and hence the maintenance easier. Since, an enterprise application may have several Web Applications as its components, hence an EAR file may contain WARs and JARs (i.e. EJB JARs). An EAR also contains an XML-based Deployement Descriptor, which is used by the Application Server to deploy the enterprise application correctly.
Creating EAR file from Command Line Interface
To create a J2EE application using the CLI, follow these steps:
- Create a working directory with this name: <working directory>
- Create the deployment descriptor application.xml if required (see below ejb-jar.xml file).
- Move the deployment descriptor, the WAR file, and the EJB JAR file to the directory that you created in step 1 . Note the EJB JAR file is simple a jar file of the classes.
- Go to your working directory.
- Execute this command: jar -cvf helloworld.ear *
This command creates the J2EE application helloworld.ear.
|
Deploytool
There is a GUI application that comes free with many J2EE server called deploytool that helps create the necessary deployment descriptor (ejb-jar.xml) file given the EJB class files. It can also be used to create the EAR file and finally to deploy it. |
|
Command Line Deployment (see documentation for your server)
Here is an example from an older J2EE server, Assuming that the directory hello (the hello.ear file) resides in /home/user, type the following command line (all on one line) to deploy the application.
% asadmin deploydir --user admin --password admin_password /home/user/hello
|
Web Interface Deployment, Glassfish
Go to web interface for J2EE server like ours at
http://puzzle.mcs.csueastbay.edu:4848
You will have to login and follow instructions contained in: J2EE tutorial w/ info on EJBs to use the GUI to deploy. Basically, you will have to point it to the EAR file discussed above another option may be to deploy as a directory.
|
Autodeploy directory
There is a special directory on the J2EE Server that is used as an autodeploy directory. Basically you deposit your ear file in this directory and it will be automatically picked up for deployment.
Application Server polls the autodeploy directory every X (e.g. 2) seconds and deploys any new, deployable units.
To change those default values:
- Log in to the Administration Console.
- Click Applications.
The Application Configurations page is displayed.
- Revise the values in the Auto Deploy Poll Interval and Auto Deploy Directory fields and then click Save.
- Shut down and restart the domain.
To undeploy a unit, simply delete it from the autodeploy directory.
Example: Glassfish directory
/opt/glassfish3/glassfish/domains/puzzle_dom1/autodeploy
|
Deployment Descriptor: ejb-jar.xml
This may be OPTIONAL when you are using annotations in code (@XXX)
XML file that describes EJB type, security and transaction parameters
From EJB Basics example, this would be the XML
deployment file (simple) you would use:
<?xml version="1.0"?>
<!DOCTYPE ejb.jar PUBLIC
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>EnrollmentCart</ejb-name>
<home>EnrollmentCartHome</home>
<remoe>EnrollmentCart</remote>
<ejb-class>EnrollmentCartEJB</ejb-class>
<session-type>Statefull</session-type>
.....
</session>
</enterprise-beans>
</ejb-jar> |
Vendor Specific Deployment Descriptors:
Again may be optional ---check out container documentation
Each vendor can specify its own deployment descriptors. These files give important
information about the pakcage name, JNDI name (for remote lookup), and security
and persistence information.
NOT Standardized.
BEA Weblogic : weblogic-ejb-jar.xml
|
JBoss : jboss.xml
|
|