Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: editing

...

JEE module

JEE deployment descriptor (DD)

Geronimo deployment plan

web application archive (warWAR)

web.xml

geronimo-web.xml

EJB application archive (jarJAR)

ejb-jar.xml

openejb-jar.xml

resource adapter archive (rarRAR)

ra.xml

geronimo-ra.xml

enterprise application archive (earEAR)

application.xml

geronimo-application.xml

enterprise application client archive (jarJAR)

application-client.xml

geronimo-application-client.xml

...

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

The geronimo-web.xml uses XML elements from http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1 namespace and one or more namespaces mentioned in Common elements and Configuration section above earlier in the document.

For example, the following web.xml and geronimo-web.xml are the deployment descriptor and Geronimo deployment plan respectively, of a web application that connects to a datasource deployed on DB2 and retrieves data from a table.

Code Block
xml
xml
borderStylesolid
titleweb.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                               http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                               version="2.5">
    
    <resource-ref>
        <res-ref-name>jdbc/DataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    
    <welcome-file-list>
        <welcome-file>jsp/EMPdemo.jsp</welcome-file>
    </welcome-file-list>
</web-app>
Note

With servlet2Servlet 2.5 specspecification, many of the declarations done through web.xml can also be done through corresponding annotations in the servlets and JSPs.

The web module connects to back end datasource using its JNDI name jdbc/DataSource as declared in the web.xml.

Code Block
xml
xml
borderStylesolid
titlegeronimo-web.xml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
          xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
          xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
          xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

     <sys:environment>
         <sys:moduleId>
             <sys:groupId>samples</sys:groupId>
             <sys:artifactId>EmployeeDemo</sys:artifactId>
             <sys:version>2.5</sys:version>
             <sys:type>war</sys:type>
         </sys:moduleId>
        
        <sys:dependencies>
             <sys:dependency>
                 <sys:groupId>samples</sys:groupId>
                 <sys:artifactId>EmployeeDatasource</sys:artifactId>
                 <sys:version>2.5</sys:version>
                 <sys:type>rar</sys:type>
             </sys:dependency>
         </sys:dependencies>
     </sys:environment>
    
     <context-root>/EmployeeDemo</context-root>

        <naming:resource-ref>
         <naming:ref-name>jdbc/DataSource</naming:ref-name>
         <naming:resource-link>jdbc/EmployeeDatasource</naming:resource-link>
     </naming:resource-ref>


 </web-app>

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 moduleId elements provide the configuration name for the web module. So, when the web module is deployed, it is given the configuration name samples/samples/2.5/jar. The dependencies elements provide the configurations and third party libraries on which the web module is dependent on. These configurations and libraries will be available to the web module via a classloader hierarchy. In this case, the web module is dependent on samples/EmployeeDatasource/2.5/rar 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.

<sys:context-root> .. </sys:context-root> : The XML elements used to provide the web context root of the web applications.

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

...

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.

Code Block
XML
XML
borderStylesolid
titleejb-jar.xml
<?xml version="1.0" encoding="UTF-8" ?> 
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
  
    <description>Stateless Session Bean Example</description> 
    <display-name>Stateless Session Bean Example</display-name> 
    
    <enterprise-beans>
        <session>
            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
            <business-remote>examples.session.stateless_dd.RetrieveEmployeeInfo</business-remote>
        <ejb-    <ejb-class>examples.session.stateless_dd.RetrieveEmployeeInfoBean</ejb-class> 
            <session-type>Stateless</session-type> 
            <transaction-type>Container</transaction-type> 
 	            
            <resource-ref>
		                <res-ref-name>jdbc/DataSource</res-ref-name>
		                <res-type>javax.sql.DataSource</res-type>
		                <res-auth>Container</res-auth>
		<res-sharing-                <res-sharing-scope>Shareable</res-sharing-scope>
	            </resource-ref>
        </session>
    </enterprise-beans>
    
    <interceptors>
        <interceptor>

            <interceptor-class>
	                   examples.session.stateless_dd.RetrieveEmployeeInfoCallbacks

            </interceptor-class>

            <post-construct>
                <lifecycle-callback-method>construct</lifecycle-callback-method>
            </post-construct>
            
            <post-activate>
                <lifecycle-callback-method>activate</lifecycle-callback-method>
            </post-activate>
            
            </interceptor<pre-class>passivate>
         <post-construct><lifecycle-callback-method>construct</lifecycle-callback-method></post-construct>
       <post-activate><lifecycle<lifecycle-callback-method>activate<method>passivate</lifecycle-callback-method></post-activate>method>
       <pre-passivate><lifecycle-callback-method>passivate</lifecycle-callback-method><     </pre-passivate>
        </interceptor>
    </interceptors>
    
  
  <assembly-descriptor>
        <interceptor-binding>

            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
-name>

            <interceptor-class>
                <interceptor-class>examplesexamples.session.stateless_dd.RetrieveEmployeeInfoCallbacks
            </interceptor-class>
        
        </interceptor-binding>
  
  </assembly-descriptor>  

</ejb-jar>

Note

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.

...

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.

Code Block
XML
XML
borderStylesolid
titleopenejb-jar.xml
<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2" 
         xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
         xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" 
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>samples</sys:groupId>
            <sys:artifactId>EmployeeDemo-ejb-dd</sys:artifactId>
            <sys:version>3.0</sys:version>
            <sys:type>jar</sys:type>
        </sys:moduleId>
       	 
         <sys:dependencies>
	            <sys:dependency>
                <sys:groupId>console.dbpool</sys:groupId>
                <sys:artifactId>jdbc%2FEmployeeDatasource<artifactId>jdbc/FEmployeeDatasource</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>rar</sys:type>
           </sys:dependency>
	        </sys:dependencies>
    </sys:environment>
	
	    
    <enterprise-beans>
		<session>
			<ejb-name>RetrieveEmployeeInfoBean</ejb-name>
			     <naming:resource-ref>
				 <naming:ref-name>
					jdbc/DataSource
   <session>
            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
            <naming:resource-ref>
             <   <naming:ref-name>jdbc/DataSource</naming:ref-name>
			                <naming:resource-link>jdbc/EmployeeDatasource</naming:resource-link>
			            </naming:resource-ref>
		        </session>
	    </enterprise-beans>
</openejb-jar>	  

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 moduleId configuration and the dependencies. The moduleid 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%2FEmployeeDatasourcejdbc/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.

...

An enterprise application archive (ear) can consist of many sub modules. The sub modules can be web modules (war), ejb modules (jar), resource adapter modules (rar) or application client modules (jar). When an ear consist of many sub modules, the deployment plans for all the sub modules can be provided in a single file named geronimo-application.xml. This single file contains the deployment details of each of the sub modules of the ear. Alternatively, each of the sub modules can package its corresponding deployment plan file within itself. However, the preferable way is to provide a single deployment plan through geronimo-application.xml for all the sub modules. This mechanism provides flexibility of allowing us to modify the deployment configuration for all modules through a single file. In this section, we explore ear deployment plan and understand what it contains.

An enterprise application archive (ear) should provide its deployment descriptor in application.xml. The application.xml lists all the sub modules in the ear file along with the descriptions. Along with the deployment descriptor, deployer should also provide Geronimo specific deployment plan in geronimo-application.xml. Along with the description of each of the sub modules of the ear file, this file also provides mappings for JEE resources that each of the sub modules refers in their deployment descriptor. The geronimo-application.xml is divided into several sections where in each section, the deployment plan for a sub module is provided. The deployment plan borrows XML elements from all other schemas. It is the highest level plan that provides deployment plan for all sub modules; hence it can contain XML elements from every other Geronimo XML schema used by Geronimo application deployer. The geronimo-application.xml is the super set of all other deployment plans.

...

The above Order.ear file contains two modules. One is OrderWEB.war file which is a web module and the other is OrderEJB.jar file which is an ejb module. The META-INF folder of Order.ear file contains the application deployment descriptor (application.xml) and the Geronimo application deployment plan (geronimo-application.xml). The web application and the ejb application have packaged only their respective deployment descriptors. But the deployment plans for these modules are provided in the geronimo-application.xml.
The web application (OrderWAR.war) looks up stateless session bean in the OrderEJB.jar module to retrieve the order information. The RetrieveOrderInfoBean in OrderEJB.jar module uses JDBC connection to read the order information from a DB2 database.

...

Code Block
XML
XML
borderStylesolid
titleejb-jar.xml
<?xml version="1.0" encoding="UTF-8" ?> 
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
             http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
  <description>Stateless Session Bean Example</description> 
  <display-name>Stateless Session Bean Example</display-name> 
 <enterprise-beans>
   <session>
     <ejb-name>RetrieveOrderInfoBean</ejb-name>
     <business-local>
         examples.session.stateless_dd.RetrieveOrderInfo
     </business-local>
     <ejb-class>
         examples.session.stateless_dd.RetrieveOrderInfoBean
     </ejb-class> 
     <session-type>Stateless</session-type> 
     <transaction-type>Container</transaction-type> 
 
	      <resource-ref>
		        <res-ref-name>
                  jdbc/DB2DataSource
                </res-ref-name>
		        <res-type>
                  javax.sql.DataSource
                </res-type>
		        <res-auth>Container</res-auth>
		        <res-sharing-scope>
                  Shareable
                </res-sharing-scope>
	      </resource-ref>
		         
	     
   </session>
 </enterprise-beans>
 
 <interceptors>
   <interceptor>
       <interceptor-class>
         examples.session.stateless_dd.RetrieveOrderCallbacks
       </interceptor-class>
       <post-construct>
         <lifecycle-callback-method>
            construct
         </lifecycle-callback-method>
       </post-construct>
       <pre-destroy>
          <lifecycle-callback-method>
              destroy
          </lifecycle-callback-method>
       </pre-destroy> 
    </interceptor>
  </interceptors> 
  
  <assembly-descriptor>
    <interceptor-binding>
      <ejb-name>RetrieveOrderInfoBean</ejb-name>
      <interceptor-class>
        examples.session.stateless_dd.RetrieveOrderCallbacks
      </interceptor-class>
    </interceptor-binding>  
  </assembly-descriptor>  
</ejb-jar>

...

Code Block
XML
XML
borderStylesolid
titleweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     id="WebApp_ID" 
     version="2.5">
  <display-name>OrderWEB</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>RetrieveOrder</display-name>
    <servlet-name>RetrieveOrder</servlet-name>
    <servlet-class>
       examples.web.servlet.RetrieveOrder
    </servlet-class>
  </servlet>
  <ejb-local-ref>
  	  <ejb-ref-name>ejb/RetrieveOrderInfo
        </ejb-ref-name>
  	  <ejb-ref-type>Session</ejb-ref-type>
  	  <local>
         examples.session.stateless_dd.RetrieveOrderInfo
        </local>
    	<ejb-link>RetrieveOrderInfoBean</ejb-link>
  </ejb-local-ref>
  <servlet-mapping>
    <servlet-name>RetrieveOrder</servlet-name>
    <url-pattern>/RetrieveOrder</url-pattern>
  </servlet-mapping>
</web-app>

...

Code Block
XML
XML
borderStylesolid
titlegeronimo-application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" 
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2" 
             application-name="Order">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>Order</sys:groupId>
      <sys:artifactId>OrderEAR</sys:artifactId>
      <sys:version>5.0</sys:version>
      <sys:type>car</sys:type>
    </sys:moduleId>
  </sys:environment>
  
    <module>
        <web>OrderWEB.war</web>
        <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" >
        <sys:environment>
            <sys:moduleId>
                	<sys:groupId>Order</sys:groupId>
                	<sys:artifactId>OrderWEB</sys:artifactId>
             	   <sys:version>2.5</sys:version>
               	 <sys:type>war</sys:type>
            	</sys:moduleId>
        </sys:environment>
 			           <context-root>/OrderDemo</context-root>
        </web-app>
    </module>
    
	    <module>
        <ejb>OrderEJB.jar</ejb>
        <openejb-jar 
         xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2" 
         xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2">

     		   <sys:environment>
environment>
            	 <sys:moduleId>
                	  <sys:groupId>Order</sys:groupId>
             	     <sys:artifactId>OrderEJB</sys:artifactId>
            	  <sys:version>3.0</sys:version>
                	  <sys:type>jar</sys:type>
          	  </sys:moduleId>
		
        
          	  <sys:dependencies>
		         <sys:dependency>
                  <sys:groupId>console.dbpool</sys:groupId>
                  <sys:artifactId>OrderDS</sys:artifactId>
                  <sys:version>1.0</sys:version>
                	  <sys:type>rar</sys:type>
                	 </sys:dependency>
		        </sys:dependencies>
            </sys:environment>
            
        <enterprise-beans>
    		</sys:environment>
    		
		<enterprise-beans>
		<session>
		<session>
         <ejb-name>RetrieveOrderInfoBean</ejb-name>
	              <naming:resource-ref>
		           <naming:ref-name>
                     jdbc/DB2DataSource
                   </naming:ref-name>
		           <naming:resource-link>
                      OrderDS
                   </naming:resource-link>
		          </naming:resource-ref>
			            </session>
		        </enterprise-beans>
	                		
        </openejb-jar>
	    </module>        
</application>

Observe how the JEE 5 resource names and ejb names in ejb-jar.xml and web.xml are mapped to actual resources deployed in the server through geronimo-application.xml.

...