You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

This article is provided a great deal of information for users to get an understanding of geronimo deployment plans for EJB.In this article will cover the structure,overview and elements of the EJB deployment plans.Basically this topic is wide broad area to discuss and it should be updated on and on with the future enhancement of geronimo.

This article is organized into the following sections : -

Basic steps to Deploy EJB in Geronimo

Typically there are several steps to be taken to deploy EJBs in Geronimo
First it needs to create the EJB classes and interfaces
Create the standard ejb-jar.xml deployment descriptor
Create a Geronimo-specific openejb-jar.xml deployment plan
Package the EJBs and deployment descriptors into an EJB JAR, or a directory tree laid out like an EJB JAR

Use the deployment tool described in deployment plan "The Deploy Tool" to deploy the EJB JAR (or an EAR containing the EJB JAR) into the server or else the use can use the geronimo web console for it.

Describing the geronimo deployment plan for EJB

Geronimo deployment plan for an EJB JAR is an XML document which is called "openejb-jar.xml".This document is defined by the openejb-jar-2.0.xsd schema,which can be found in the <geronimo-home>/schema/ subdirectory of the main Geronimo installation directory.The deployment plan for an EJB JAR may be included in the EJB JAR, in which case it should be named META-INF/openejb-jar.xml or included in an EAR (but outside of the EJB JAR) and referenced by an alt-dd element of the EAR deployment plan or else Saved as a separate file and provided to the deploy tool when the EJB JAR module is deployed (though this doesn't work when the EJB JAR is in an EAR).

The deployment plan should always use the OpenEJB namespace, and it typically requires elements from the Geronimo Naming, Geronimo Security, and Geronimo System namespaces. Additionally, it has a required attribute to identify its configuration name, and an optional attribute to select a parent configuration.a Typical deployment for openejb-jar.xml can be presented as follows.

<openejb-jar
xmlns:openejb="http://www.openejb.org/xml/ns/openejb-jar-2.1"
    targetNamespace="http://www.openejb.org/xml/ns/openejb-jar-2.1"
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
    xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
    xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
    version="1.0">
...
</openejb-jar>

xmlns
The main namespace for the deployment plan, which should always be http://www.openejb.org/xml/ns/openejb-jar-2.1

xmlns:naming

A secondary namespace, used to identify the common elements for resolving EJB references, resource references, and web services references. If any of those need to be resolved in the deployment plan, this attribute should be present, and should be set to http://geronimo.apache.org/xml/ns/naming-1.1

xmlns:security
A secondary namespace, used to identify the common elements for security configuration. If there are any security settings in the deployment plan, this attribute should be present, and should be set to http://geronimo.apache.org/xml/ns/security-1.1

xmlns:sys
A secondary namespace, used to identify the common elements for common libraries and module-scoped services. If there are any of those present in the deployment plan, this attribute should be present, and should be set to http://geronimo.apache.org/xml/ns/deployment-1.1

xmlns:pkgen
A secondary namespace, used to identify the common elements for configuring automatic primary key generation for CMP entity beans (such as, using a sequence or auto-increment column). If there are any primary key generators present in the deployment plan, this attribute should be present, and should be set to http://www.openejb.org/xml/ns/pkgen-2.0

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
        <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
                <dep:moduleId>
                        <dep:groupId>default</dep:groupId>
                        <dep:artifactId>BankEJB</dep:artifactId>
                        <dep:version>1.0</dep:version>
                        <dep:type>car</dep:type>
                </dep:moduleId>
                <dep:dependencies/>
                <dep:hidden-classes/>
                <dep:non-overridable-classes/>
        </dep:environment>
        <cmp-connection-factory>
                <resource-link>BankPool</resource-link>
        </cmp-connection-factory>
        <enterprise-beans>
                <session>
                        <ejb-name>BankManagerFacadeBean</ejb-name>
                        <jndi-name>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean</jndi-name>
                        <ejb-ref>
                                <ref-name>ejb/Customer</ref-name>
                                <ejb-link>Customer</ejb-link>
                        </ejb-ref>
                        <ejb-ref>
                                <ref-name>ejb/Account</ref-name>
                                <ejb-link>Account</ejb-link>
                        </ejb-ref>
                        <ejb-ref>
                                <ref-name>ejb/ExchangeRate</ref-name>
                                <ejb-link>ExchangeRate</ejb-link>
                        </ejb-ref>
                </session>
                
                <entity>
                        <ejb-name>Account</ejb-name>
                        <local-jndi-name>AccountLocalEntity</local-jndi-name>
                        <table-name>Account</table-name>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>accountNumber</cmp-field-name>
                                <table-column>ACC_NO</table-column>
                        </cmp-field-mapping>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>accountType</cmp-field-name>
                                <table-column>ACC_TYPE</table-column>
                        </cmp-field-mapping>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>customer</cmp-field-name>
                                <table-column>CUSTID_FK</table-column>
                        </cmp-field-mapping>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>balance</cmp-field-name>
                                <table-column>BALANCE</table-column>
                        </cmp-field-mapping>
                        
                        <resource-ref>
                                <ref-name>jdbc/BankDataSource</ref-name>
                                <resource-link>BankPool</resource-link>
                        </resource-ref>
                </entity>
                
                <entity>
                        <ejb-name>Customer</ejb-name>
                        <local-jndi-name>CustomerLocalEntity</local-jndi-name>
                        <table-name>Customer</table-name>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>customerId</cmp-field-name>
                                <table-column>CUST_ID</table-column>
                        </cmp-field-mapping>
                        
                        <cmp-field-mapping>
                                <cmp-field-name>customerName</cmp-field-name>
                                <table-column>CUST_NAME</table-column>
                        </cmp-field-mapping>
                        
                        <resource-ref>
                                <ref-name>jdbc/BankDataSource</ref-name>
                                <resource-link>BankPool</resource-link>
                        </resource-ref>
                </entity>
                
                <entity>
                        <ejb-name>ExchangeRate</ejb-name>
                        <local-jndi-name>ExchangeRate</local-jndi-name>
                        <resource-ref>
                                <ref-name>jdbc/BankDataSource</ref-name>
                                <resource-link>BankPool</resource-link>
                        </resource-ref>
                </entity>
        </enterprise-beans>

        <relationships>
                <ejb-relation>
                        <ejb-relation-name>Customer-Account</ejb-relation-name>
                        <ejb-relationship-role>
                                <ejb-relationship-role-name>Account-to-Customer</ejb-relationship-role-name>
                                <relationship-role-source>
                                        <ejb-name>Account</ejb-name>
                                </relationship-role-source>
                                <cmr-field>
                                        <cmr-field-name>customer</cmr-field-name>
                                </cmr-field>
                                <foreign-key-column-on-source/>
                                <role-mapping>
                                        <cmr-field-mapping>
                                                <key-column>CUST_ID</key-column>
                                                <foreign-key-column>CUSTID_FK</foreign-key-column>
                                        </cmr-field-mapping>
                                </role-mapping>
                        </ejb-relationship-role>
                </ejb-relation>

        </relationships>

</openejb-jar>

The Structural over view of EJB Deployment Plan

In a Ejb Deployment plan there are main attributes defined in the top.

configIdrequiting
A unique name identifying this module. If deployed as a standalone EJB JAR, this name is used to identify the module to the deployment tool (to start, stop, undeploy, or redeploy the EJB JAR).

parentId
Identifies the parent configuration for this EJB JAR (the value specified here should match the configId for that module). If deployed as a standalone EJB JAR, this can be used to make the EJB JAR depend on another module such as another standalone EJB JAR or a J2EE Connector (or it should otherwise be omitted or set to the usual parent for J2EE modules, geronimo/j2ee-server/1.0/car).

inverseClassloading
If set to true, the class loader for the EJB JAR tries to load a class before checking whether the class is available from its parent class loader. configId
A unique name identifying this module. If deployed as a standalone EJB JAR, this name is used to identify the module to the deployment tool (to start, stop, undeploy, or redeploy the EJB JAR).

parentId
Identifies the parent configuration for this EJB JAR (the value specified here should match the configId for that module). If deployed as a standalone EJB JAR, this can be used to make the EJB JAR depend on another module such as another standalone EJB JAR or a J2EE Connector (or it should otherwise be omitted or set to the usual parent for J2EE modules, geronimo/j2ee-server/1.0/car). If deployed as part of an EAR this is usually not necessary, as EAR configuration will be the parent of this module.

inverseClassloading
If set to true, the class loader for the EJB JAR tries to load a class before checking whether the class is available from its parent class loader. If omitted or set to false, the normal (check parent first) class loader delegation behavior is used

Typical contents of Geronimo EJB Deployment Plan

There are some typical contents of the Geronimo EJB Deployment Plan has been identified as and it has described follows

Security settings indicating which users and roles should be able to access secure EJBs or secure EJB methods
Details to resolve EJB references, resource references, and web services references declared by EJBs in the ejb-jar.xml deployment descriptor. This isn't always necessary for EJB references (which may be resolved using an ejb-link in the ejb-jar.xml) but generally is for the other types of references.
JNDI names for each EJB, used by remote clients attempting to connect to the EJB.
Web Services settings, for session beans exposed as web services.
Database pool, table, column, query, and relationship information for CMP Entity Beans.
JMS mapping information for Message-Driven Beans.
For the simplest EJB JARs these settings may not be required or the defaults may be sufficient, but in most cases the Geronimo EJB deployment plan will need a substantial amount of information.
As usual in other geronimo deployment plans open-ejb.jar has specific structure and element followed in an order.

Geronimo Deployment path settings

The elements in the classloader-infoGroup are used to customized the EJB JAR's class.There are four elements need to be discussed under class path settings.

import

Refers to another configuration deployed in the server. That configuration will be added as a parent of this one (a configuration may have more than one parent). The main effect is that the class loader for the EJB JAR will add the class loader for that configuration as a parent. Additionally, the parent configuration will be started before the EJB JAR.

dependency
Adds a third-party library to the class path for the EJB JAR. Any common libraries used in this manner should be located in a subdirectory of the repository/ directory of the main Geronimo installation.

hidden-classes

Lists packages or classes that may be in a parent class loader, but should not be exposed from there to the EJB JAR. This is typically used when the EJB JAR wants to use a different version of a library that one of its parent configurations (or Geronimo itself) uses.

non-overridable-classes

Lists packages or classes that the EJB JAR should always load from a parent class loader, and never load from its own class loader. This might be used to force an EJB to share the same instance of a common library with other applications or modules, even if they each include it in their own class path.

filter
Used to list classes or packages. The format is a comma-separated list of packages or fully-qualified class names (for example: javax.servlet,javax.ejb).

When Considering the JMS and MDB Sample given(link the sample application) and it dosen't have any dependencies and imports.

<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1" xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>samples</sys:groupId>
      <sys:artifactId>OrderEjb</sys:artifactId>
      <sys:version>1.0</sys:version>
      <sys:type>car</sys:type>
    </sys:moduleId>

h3. Deploying JAR containing Simple EJB application

This section will cover Geronimo v1.1 deployment plan for the simple helloworld ejb.
Here is the folder structure for the above simple application.Sample Application is available to download here
[HelloWorld ejb Sample|^HelloWorld.tar.gz]
{code:java}
HelloWorld
   |_ejbModule
   |          |_org.geronimo.ejbsample
   |          |                 |_HelloBean
   |          |                 |_HelloHome
   |          |                 |_HelloObject
   |          |
   |          |_org.geronimo.ejbsample.client
   |                                    |_HelloWorld
   |_META-INF
   |      |_ejb-jar.xml
   |      |_openejb-jar.xml
   |
   |_dist
   |_build
   |_build.xml

Here is the ejb-jar.xml for the above sample

ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>HelloBean</ejb-name>
      <home>org.geronimo.ejbsample.HelloHome</home>
      <remote>org.geronimo.ejbsample.HelloObject</remote>
      <ejb-class>org.geronimo.ejbsample.HelloBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>HelloBean</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-jar>

Geronimo v1.1 deployment plan for the above sample

openejb.jar
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
  <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
    <dep:moduleId>
      <dep:groupId>org.geronimo.</dep:groupId>
      <dep:artifactId>ejbsample</dep:artifactId>
      <dep:version>1.0</dep:version>
      <dep:type>car</dep:type>
    </dep:moduleId>
    <dep:dependencies/>
    <dep:hidden-classes/>
    <dep:non-overridable-classes/>
  </dep:environment>
  <enterprise-beans>
    <session>
      <ejb-name>HelloBean</ejb-name>
      <jndi-name>org.geronimo.ejbsample.HomeBean</jndi-name>
    </session>
  </enterprise-beans>
</openejb-jar>

Steps to deploying the sample

There are two ways in which the sample can be deployed :-

1. The sample can be built from scratch using the build.xml and editing the geronimo_home as your directory. Obtain the helloworld-ejbs.jar from the dist directory and use the Geronimo web console. Browse for the helloworld-ejbs.jar file and click on the Install button.

2.Use the following command line code to deploy the application.

 

Running the Client to test the HelloWorld EJB service

org.geronimo.ejbsample.client.HelloWorld.java is the client code for the above application.Set the necessary class path to run client in your environment.

< <app-home>/org/geronimo/ejbsampleclient> >java HelloWorld

You will see the "Hello world" print on your command line
HelloWorld/org/geronimo/ejbsampleclient>
  Hello World!

*Image needed to be upload.

  • No labels