One of the big advantages of Enterprise JavaBeans is the ability to
package and distribute server-side logic in the same portable fashion
as GUI components. In this step the source files from the preceeding
steps are compiled and then packaged into an ejb-jar
file.
By completing the four steps below you will produce the Demo.jar
ejb-jar
file, which will then be ready for deployment, or installation,
into the Enterprise JavaBeans Container.
-
Compile the
.java
Files
-
Create the
DeploymentDescriptor
-
Make sure
you have all the pieces
-
Create the
ejb-jar
file
1. Compile the .java
Files
Run javac
on the files you have just created, that is, the
home and remote interfaces, and the Enterprise JavaBeans bean itself.
javac ejb/demo/DemoHome.java
javac ejb/demo/Demo.java
javac ejb/demo/DemoBean.java
2. Create the Deployment Descriptor
Note: Deployment is the Enterprise
JavaBeans term for installing the Enterprise JavaBeans components
into an Enterprise JavaBeans container.
The role of the deployment descriptor is to allow the bean
deployer
to customize many of the properties of the bean
prior to deployment
. The deployment
descriptor is
described in the Enterprise JavaBeans Specification (section 15.2) as an
instance of either javax.ejb.deployment.SessionDescriptor
or javax.ejb.deployment.EntityDescriptor
. In the DemoBean
example, it is an instance of the
javax.ejb.deployment.SessionDescriptor
. Below is an
example of the text file input to WebLogic's utilities that generate
the serialized instance of this deployment
descriptor.
Note that the methodology for creating the deployment
descriptor is not specified, so the tools used to generate and
deploy
Enterprise JavaBeans may look
and feel very different from each other, without affecting the
cross-platform deployment abilities of the beans themselves.
The example below continues with creating the DeploymentDescriptor
with the WebLogic tools. The BEA Weblogic server implementation
offers both command line and GUI deployment tools. So to deploy the
Enterprise JavaBean using the command line tools, issue the following
commands:
java weblogic.ejb.utils.DDCreator -dir ejb/demo
ejb/demo DeploymentDescriptor.txt
This will create DemoBeanDD.ser
in the ejb/demo
directory.
An example DeploymentDescriptor.txt textfile for input to the
BEA Weblogic tools
(source):
(SessionDescriptor
; This file must start with SessionDescriptor or
; EntityDescriptor
; Indicate the name which the bean will be bound
; into the JNDI name as
beanHomeName demo.DemoHome
; The enterprise Java Bean class (see step 4)
enterpriseBeanClassName ejb.demo.DemoBean
homeInterfaceClassName ejb.demo.DemoHome
; The home interface implemented by a class
; generated by the container provided tools
; see step 3
remoteInterfaceClassName ejb.demo.Demo
; See step 2
isReentrant false
; Always false for session beans
stateManagementType STATELESS_SESSION
; Either STATELESS_SESSION or STATEFUL_SESSION.
; DemoBean is a stateless session bean
sessionTimeout 5
; seconds
(controlDescriptors
; This section decides the run-time properties when
; a method is called. The DEFAULT sub-section applies
; to all methods, but can be overridden on a per-method
; basis, similar to the "accessControlEntries" above.
(DEFAULT
isolationLevel TRANSACTION_SERIALIZABLE
transactionAttribute TX_REQUIRED
runAsMode CLIENT_IDENTITY
)
; end isolationLevel
)
; end controlDescriptors
(environmentProperties
maxBeansInFreePool 100
)
; end environmentProperties
)
; end SessionDescriptor
Note: This example is for the BEA Weblogic server
which uses the semi-colon (;) to comment out lines.
3. Create The Manifest
The manifest is automatically generated by the jar
utility, but will take a template, so create a text file (for example,
ejb/demo/manifest.txt
) with the contents below. Refer to
the next section on packaging the bean to see how this text file is used.
For a description of the manifest file, see the
Enterprise JavaBeans
Specification, Section 15.3.
Name: ejb/demo/DemoBeanDD.ser
Enterprise-Bean: True
4. Make Sure You Have all the pieces
Here are the pieces the Enterprise JavaBeans developer and provider
need to supply to create a valid ejb-jar
file, that is, the
Enterprise JavaBeans bean:
- The enterprise bean class + any other classes the
bean depends upon (Step 4).
- The enterprise bean's remote interface (Step 2).
- The enterprise bean's home interface (Step 3).
-
A deployment
descriptor (see above).
- An instance of
java.util.Properties
, if needed by the bean.
- A manifest file that identifies the
deployment descriptors in the
ejb-jar
file.
See the Enterprise JavaBeans Specification, section 16, for more details.
The Enterprise JavaBeans bean provider is responsible for putting all of
these classes into the ejb-jar
file, but it is expected that
most of the container and server providers will provide tools for doing
this packaging and assembly.
The Manifest
The manifest is automatically generated by the jar
utility, but will take a template, so create a text file (for example,
ejb/demo/manifest.txt
) with the contents below. Refer to
the next section on packaging the bean to see how this text file is used.
For a description of the manifest file, see the
Enterprise JavaBeans
Specification, Section 15.3.
Name: ejb/demo/DemoBeanDD.ser
Enterprise-Bean: True
5. Create the ejb-jar
file
For the example you simply jar all the pieces together to make a jar file
called Demo.jar
. It is expected that future tools will make
the packaging and the generation of the ejb-jar
file much
easier. You can imagine a GUI wizard leading you through and checking
dependencies here very easily.
To create the ejb-jar
file Demo.jar
for the
example, you can assume the pieces of the jar file are all under a
directory called ejb
. You simply create a jar file of
this directory structure.
Notes: Use the m
flag to jar and
ejb/demo/manifest.txt
as a template for the manifest.
It is not necessary to put the manifest.txt
into the
jar file.
jar cvfm Demo.jar ejb/demo/manifest.txt ejb/demo/*.class \
ejb/demo/*.ser
Inspecting the Demo.jar
should produce output similar to:
jar tf Demo.jar
META-INF/MANIFEST.MF
ejb/demo/Demo.class
ejb/demo/DemoBean.class
ejb/demo/DemoHome.class
ejb/demo/DemoBeanDD.ser
So as you can see, there is nothing too special about the ejb-jar
file.
<< BACK
NEXT >>