How to control the initialization order of an EAR's subdeployments / modules in JBoss Enterprise Application

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Issue

  • How to control the initialization order of an EAR's subdeployments / modules in JBoss EAP?
  • Is there a way to maintain the deployment order mentioned in the application.xml file in JBoss EAP?
  • While trying to deploy 2 ejb jars in one EAR on JBoss EAP following kind of exception is observed. Where the EJB jar1 is dependent on EJB jar2.
16:19:26,326 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"EAR_1.ear\".\"EJBOne.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"EAR_1.ear\".\"EJBOne.jar\".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment \"EJBOne.jar\" of deployment \"EAR_1.ear\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014183: Bean class test.ejb.one.TestClass specifies @Local annotation, but does not implement 1 interface"},"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.comp.EAR_1.testEJBTwo.FormatMapperSE.ValidatorFactory Missing[jboss.naming.context.java.comp.EAR_1.testEJBTwo.FormatMapperSE]","jboss.naming.context.java.comp.EAR_1.common.ejb.ValidatorFactory Missing[jboss.naming.context.java.comp.EAR_1.testEJBTwo.OnlineRequestSI]","jboss.naming.context.java.comp.EAR_1.testEJBTwo.TestBranch.ValidatorFactory Missing[jboss.naming.context.java.comp.EAR_1.testEJBTwo.TestBranch]","jboss.deployment.subunit.\"EAR_1.ear\".\"TestWebApp.war\".INSTALL 
  • The same application worked when all the EJB jar1 and EJB jar2 contains are merged into one JAR and then placed inside an EAR.
  • Unable to deploy an EAR with 2 ejb modules where one is dependent on other .

Resolution

  • Set initialize-in-order to true in the EAR's META-INF/application.xml and list the sub deployments in the order from top to bottom that you would like them initialized / started.

  • In the example below, test2.war will be started first, followed by my-ejb.jar and finally test.war:

<?xml version="1.0" encoding="UTF-8"?>
<application version="8"
        xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/application_8.xsd" >

     <initialize-in-order>true</initialize-in-order>

     <module>
         <web>
             <web-uri>test2.war</web-uri>
             <context-root>test2</context-root>
         </web>
     </module>
     <module>
         <ejb>my-ejb.jar</ejb>
     </module>
     <module>
         <web>
             <web-uri>test.war</web-uri>
             <context-root>test</context-root>
         </web>
     </module>
</application>

Note

  • If "<initialize-in-order>" is true, modules must be initialized in the order they're listed in this deployment descriptor, with the exception of application client modules, which can be initialized in any order.

  • If "<initialize-in-order>" is not set or set to false, the order of initialization is unspecified, and may be product-dependent.

Related Solutions

  1. How to declare classloading dependencies between deployments in JBoss EAP 6

  2. How to control the order of deployed applications on JBoss Enterprise Application 6

  3. How to declare service lifecycle dependencies (such as EJB) between deployments in JBoss EAP 6

Root Cause

An application can declare that modules must be initialized in the order they’re listed in the application deployment descriptor by including the <initialize-in-order>true</initialize-in-order> element in the application deployment descriptor.
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.