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

Compare with Current View Page History

« Previous Version 9 Next »

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

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.

This article is organized into the following sections : -

Describing the geronimo deployment plan for EJB

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>

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