Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Step 5: Creating the ejb-jar file

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 following the 4 steps below you will produce the Demo.jar ejb-jar file, which will then be ready for Deployment (installation) into the EJB Container.
  1. Compiling the .java files
  2. Creating the DeploymentDescriptor
  3. Make sure you have all the pieces
  4. Create the ejb-jar file

1. Compiling 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


2. Creating the Deployment Descriptor

Reminder: Deployment is the EJB term for installation of the Enterprise JavaBeans components into an EJB 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 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 affecting 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 only from 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):


  [BEGIN SESSION DESCRIPTOR]

  SessionDescriptor
   (This file must start with SessionDescriptor 
     or EntityDescriptor)

  [Enter the name by which the bean will be 
  bound into the JNDI name space.] 
    beanHomeName demo.DemoHome
  
  [Enter the enterprise JavaBean class]
    enterpriseBeanClassName ejb.demo.DemoBean 
    (see Step 4) 
   
  [Enter the home interface implemented by a class 
  generated by the container provided tools]
    homeInterfaceClassName ejb.demo.DemoHome
    (see Step 3)
   
  [Declare the remote interface class name] 
    remoteInterfaceClassName ejb.demo.Demo
    (see Step 2)
  
  isReentrant false is always false for session beans
  
  [Enter the stateManagementType]
  stateManagementType STATELESS_SESSION
   (Either STATELESS_SESSION or STATEFUL_SESSION)
   (DemoBean is a stateless session bean)
  
  sessionTimeout 5 seconds

    [BEGIN CONTROL DESCRIPTORS]
      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.) 
      
      [BEGIN ISOLATIONLEVEL]
        {DEFAULT isolationLevel 
        TRANSACTION_SERIALIZABLE
        transactionAttribute TX_REQUIRED
        
        runAsMode CLIENT_IDENTITY 
        }; 
        end isolationLevel
      [END ISOLATION LEVEL]
       
      }; 
      end controlDescriptors
    [END CONTROL DESCRIPTORS]
    
      [BEGIN ENVIRONMENT PROPERTIES]
        {environmentProperties
        MaxBeansInFreePool 100
        }; 
        end environmentProperties
      [END ENVIRONMENT PROPERTIES]

    }; 
    end SessionDescriptor
   [END SESSION DESCRIPTOR]


3. Make sure you have all of the pieces

Here are the pieces the EJB developer and provider needs to supply to create a valid ejb-jar file, that is, the EJB 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 EJB specification, section 16, for more details.

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

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

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


4. Create the ejb-jar file

For the example you 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 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 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.

<< BACK NEXT >>


[ This page was updated: 5-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.