Step #5: Create the ejb-jar file
- Compile the
.java files
- Create the DeploymentDescriptor
- Make sure you have all the pieces
- Create the ejb-jar file
Compile the .java files
Run javac on the files you have just created, that is, the home and remote interfaces and the EJB bean itself.
javac ejb/demo/DemoHome.java
javac ejb/demo/Demo.java
javac ejb/demo/DemoBean.java
Create the Deployment Descriptor
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 EJB specification (section 15.2) as an instance of either javax.ejb.deployment.SessionDescriptor or javax.ejb.deployment.EntityDescriptor . In our 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 EJBs may look and feel very different from each other, without effecting the cross-platform deployment abilities of the beans themselves.
The example continues below with creation of the DeploymentDescriptor with the WebLogic tools. Currently the tools are very basic and operate onlyfrom the command line, however they will become more sophisticated over time.
java weblogic.ejb.utils.DDCreator -dir ejb/demo DeploymentDescriptor.txt
This will create DemoBeanDD.ser in the ejb/demo directory.
An example DeploymentDescriptor.txt textfile for input to the 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 space as
beanHomeName
demo.DemoHome
; The enterprise JavaBean class (see step #4)
enterpriseBeanClassName
ejb.demo.DemoBean
; The home interface implemented by a class generated by the
: container provided tools see step #3
homeInterfaceClassName
ejb.demo.DemoHome
; Declare the remote interface class name
; See step #2
remoteInterfaceClassName
ejb.demo.Demo
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
Make sure you have all of the pieces
The EJB specification (see section 16) details the pieces the EJB developer/provider needs to supply to create a valid ejb-jar file, that is, the EJB bean; these are:
- 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.
The EJB 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. |