Creating deployment plans for EJB applications has been edited by Ying Tang (Jun 10, 2009).

(View changes)


Geronimo uses OpenEJB container for providing ejb services. With the advent of Java EE 5, the ejb container services such as transaction management, security, life cycle management can be declared in the ejb class itself using annotations. However, the ejb deployment descriptor can still be provided through ejb-jar.xml file. When both annotations and ejb-jar.xml file are provided, the ejb-jar.xml file takes precedence over the annotations.

The openejb-jar.xml file contains deployment plan for ejb modules. In the openejb-jar.xml file, the application deployer maps the security roles, ejb names, database resources, JMS resources, etc. declared in ejb-jar.xml file to corresponding entities deployed in the server. In addition to that, if there are any ejb container specific configurations to be done, the required settings are configured as well here. If the ejb module depends on any third party libraries or other services running in the server, all these third party libraries and the services are specified in the openejb-jar.xml file. Some ejb applications require class loading requirements different from the default class loading behavior. The openejb-jar.xml file allows application deployer to configure this as well. There are many more configurations that could be done through openejb-jar.xml file depending on the needs of the ejb application. The following sections briefly explain how openejb-jar.xml file can be used to configure the ejb container and ejb applications.

For example, the below XML content is the deployment descriptor (ejb-jar.xml) of a stateless session bean that connects to a back end DB2 database.

<?xml version="1.0" encoding="UTF-8" ?> 
<ejb-jar xmlns="" version="3.0" 
         xsi:schemaLocation=" ">
    <description>Stateless Session Bean Example</description> 
    <display-name>Stateless Session Bean Example</display-name> 






The default namespace of the above XML document is The XML elements that do not have a namespace prefix belong to the default namespace.

In EJB3.0, most of the deployment descriptor declarations can be done through the corresponding annotations in the bean class. However, if a deployment descriptor is supplied (ejb-jar.xml), the declarations in the deployment descriptor will override the annotations.

The ejb module connects to back end datasource using its JNDI name jdbc/DataSource as declared in the ejb-jar.xml. It also declares that the ejb is a stateless session bean and provides an interceptor class for the bean. The interceptor class will have callback methods which container calls when the corresponding events occur in the bean's life cycle.

For the above deployment descriptor, we will have to provide a corresponding deployment plan file (openejb-jar.xml) that maps the declared datasource to actual datasource deployed in the server. The following is the deployment plan.

<openejb-jar xmlns="" 

The default namespace of the above XML document is The XML elements that do not have a namespace prefix belong to the default namespace.

Observe the various XML tags and corresponding namespaces used in the deployment plan for various purposes.

<sys:environment> .. </sys:environment> : These elements provide the moduleId configuration and the dependencies. The moduleId elements provide the configuration name for the ejb module. So, when the ejb module is deployed, it is given the configuration name samples/EmployeeDemo-ejb-dd/3.0/jar. The dependencies elements provide the configurations and third party libraries on which the ejb module is dependent on. These configurations and libraries will be available to the ejb module via a classloader hierarchy. In this case, the ejb module is dependent on console.dbpool/jdbc/FEmployeeDatasource/1.0/jar which is the configuration of the deployed Datasource that connects to a back end DB2 database. The Datasource deploys a database connection pool (javax.sql.Datasource) with name jdbc/EmployeeDatasource.

<enterprise-beans> .. </enterprise-beans> : These elements help us to configure the enterprise beans. In this case, the datasource reference jdbc/DataSource is mapped to jdbc/EmployeeDatasource.

In the ejb bean class, the following java code is used to obtain a connection from the datasource.
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
Connection con = ds.getConnection();

The above descriptor and plan are the simple illustrations that explain how ejb modules are developed and assembled for Apache Geronimo. Similarly, many other configurations can be performed in the openejb-jar.xml. The schema for the plan is openejb-jar-2.1.xsd

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences