Step #5:  Create the ejb-jar file
        1. Compile the .java files
        2. Create the DeploymentDescriptor
        3. Make sure you have all the pieces
        4. 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.
 

The Manifest

The manifest file is described in section 15.3 of the EJB specification.

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.



Name: ejb/demo/DemoBeanDD.ser
Enterprise-Bean: True


Create the ejb-jar file

For our example we simply jar all of 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 our example, we assume the pieces of the jar file are all under a directory called ejb. We simply create a jar file of this directory structure.

Notes

a) We are using the "m" flag to jar and ejb/demo/manifest.txt as a template for our 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 give something 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.




previous next