5 Replies Latest reply on Dec 21, 2012 4:52 AM by conor roche

    How to control class loading order between 2 ears

    conor roche Newbie

      Hi,

       

      I am using jboss 7.1.3 in standalone mode where I have ear files in the deployments folder.

      I have 2 separate ears where one ear's ejb jar depends on the classes of another ear's ejb jar, and i can not get them to start consistently in the correct order.

      This results in intermittent class not found errors on startup when the 2nd ears ejb module loads before the other which prevents the ears from starting.

       

      If for example the ear structure is this:

       

      master.ear

           master-ejb.jar

       

      slave.ear

           slave-ejb.jar

       

      where slave-ejb.jar depends on master-ejb.jar

       

      I have tried controlling the order as follows:

       

      a) adding a Dependencies reference to the MANIFEST.MF of the slave-ejb jar: Dependencies:deployment.master.ear.master-ejb.jar

      b) adding a top level deployment module dependency on the ear to slave.ear's jboss-deployment-structure.xml:

       

      <deployment>

              <dependencies>

                  <module name="deployment.master.ear.master-ejb.jar"/>

              </dependencies>

          </deployment>

       

      c) adding a sub deployment module dependency on the ear to the slave.ears jboss-deployment-structure.xml:

       

      <sub-deployment name="slave-ejb.jar">

              <dependencies>

                  <module name="deployment.master.ear.master-ejb.jar"/>

             </dependencies>

      </sub-deployment>

       

      d) renaming the ear files to ensure master comes first

      e) making the module dependency optional

       

      While the above will make the master classes available to the slave module (when they intermittently startup in the right order) none of the above allow me to make the class loading sequential, presumably because of the concurrent module class loader.

       

      I can not copy the required master classes into the slave ear as they are used for local jndi and would be different classes in different class loaders so jndi will not work.

      I suspect there are 2 workarounds that i have (neither of which is ideal as will require a large amount of project restructuring for us as we actually have a lot more than 2 ears):

       

      1) Split the shared ejb client interfaces and pojos into a separate module and put in the modules dir and have both ears depend on it

      2) Merge the 2 ejbs into a single ear

       

      In JBoss 4.2.3GA the same apps worked because ears would a) load based on the file name eg. we could use this to control ear load order and b) because the ears ejb jars were loaded into the UCL

       

      Does anyone know of a way to allow make the modules class loader support some form of sequential module class loading?

        • 1. Re: How to control class loading order between 2 ears
          Nicklas Karlsson Master

          As you have found out, options a) - e) don't work. I don't think there is any natural way for inter-ear class-dependencies because the EE spec probably thinks it's no-no. You can probably fiddle around with @Singleton @Startup @DependsOn  but I think that will be for the singletons only and won't effect the classloading since they deployment is parallel in general. A natural solution would probably be the 1) option (module).

          • 3. Re: How to control class loading order between 2 ears
            conor roche Newbie

            yes i have read  every as7 class loading document/forum post that i can find on this including the one you have suggested (i post as a last resort) and none of them have lead me to a solution for the specific load order issue i'm having. The actual dependency hierarchy i have is much more complex than the simple example i posted, e.g. its more like: C depends on A and B, D depends on C, E depends on B and D, F depends on B,E and C etc

            What i have observed is that using the jboss-deployment-structure.xml like below for dependency references does appear to control load order for "some" of the sub tree of dependency ears i have e.g. having a certain tree will work 99% of the time (though can still fail with module load timeouts or rarely use the wrong order), but once i add a specific ear that depends on other ears it never loads that one in the correct order (and i am certain there are no transitive/circular deps and nothing different about the ear im adding) so from what i have seen load order may or may not work depending on the specific dependency hierarchy and or number of components.

             

            <sub-deployment name="slave-ejb.jar">

                    <dependencies>

                        <module name="deployment.master.ear.master-ejb.jar"/>

                   </dependencies>

            </sub-deployment>

             

            as a workaround i am going to instead change the start scripts to clear the deployments dir, start jboss, then use a script that will copy/cli deploy components from a holding dir into jboss in the specific order which will save me having to do any ear restructuring

            • 4. Re: How to control class loading order between 2 ears
              Stephen Coy Master

              Are you doing global JNDI lookups or do you have proper ejb-refs and looking up "java:comp/env/someEJBname"? With the latter, I believe that AS7 works out the dependencies for you.

              • 5. Re: How to control class loading order between 2 ears
                conor roche Newbie

                thanks for the suggestion, i am using the ejb3.1 global namespace for the jndi lookups e.g. java:global[/<app-name>]/<module-name>/<bean-name>[!<interface-FQN>], one thing I notice is if i start jboss with say ears A,B,C,D in deployments then A,B,C,D start in the correct order and then drop in E, E will start ok, but if i start with A,B,C,D,E it wont so i suspect a module load order bug as i cant see any reason why the A-D tree works via the jboss-deployment-descriptor dependencies but A-E doesnt, anyways for now i'l hold off adding in ejb-refs as there are a lot of ejbs. i will try the scripted sequential deployment post start, if i have time i will look into whether ejb refs control the load order cross ears  and post what i find