9 Replies Latest reply on Nov 22, 2006 5:51 AM by skosonen

    JBoss Unified ClassLoader Hell? even with EJB3 ?

    xnuandax

      Hi all,

      I am trying something usually unadvisable in JBoss which is to deploy a WAR and an EAR in the same JBoss instance (where the WAR accesses the EAR via JNDI/RMI).

      I am using JBoss 4.0.5.GA EJB3RC9, and as one might expect I am swimming in a soup of ClassCastExceptions whilst trying to use the object (remote interface) retrieved by a context.lookup().

      I have turned everything to Pass-by-Value (Naming, etc.) in jboss-service and ejb-deployer.

      My remote interface is:

      @Remote
      public Interface ManagerRemote extends Serializable {
      ...



      My SFSB is:
      @Stateful
      @Remote ({ManagerRemote.class}
      @RemoteBinding (jndiBinding="MYAPP/Manager/remote")
      public class ManagerBean implements ManagerRemote {
      ...
      


      The client in the WAR attempts to access this remote interface by:
      Context context = new InitialContext();
      object = context.lookup("MYAPP/Manager/remote");
      ManagerRemote mr = (ManagerRemote) object;
      


      I have printed the interfaces implemented by the object retrieved over JNDI, and it definitely implements "ManagerRemote" as hoped. Sadly "ManagerRemote" will not cast to "ManagerRemote", presumably because the JBoss classloader is distinguishing between the ManagerRemote interface packaged in the EAR and the same interface packaged in the WAR.

      Investigations have shown alot of issues around this, and people talking about having to play with settings like "Java2ClassLoadingCompliance", "UseJBossWebLoader" and "java2ParentDelegation" to get any joy (although I have not).

      Is it really still that hard to have a WAR and an EAR in the same JBoss instance with the same interfaces classes in each? (we are building this way as eventually the WAR and EAR won't be colocated). Are there some instructions on how to achieve this kind of setup in JBoss 4.0.5 EJB3 without an endless struggle of ClassCastExceptions ?

      Thanks!

      David



        • 1. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
          andyd

          How about running 2 instances of JBoss on the same machine, one for your EAR and the other for your WAR? Just a thought.
          Andy.

          • 2. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?

            The only way I have gotten this type of setup to work is by packaging both apps as ears. One EJB3 ear and one WAR inside an ear. Then, have each ear include a jar with the common interfaces and use scoped loader repository entries in your jboss-app.xml in each ear.

            This, along with the call-by-value, etc, should allow you to do what you want without the CCE's. You gain the added benefit of being able to hot deploy any part of the app without restarting.

            Hope this helps,
            gary.

            • 3. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
              xnuandax

              Thanks guys - no luck tho - trying two EAR deployments sounded hopeful (with one EAR just being a skin for the WAR) - surely that would give classloader isolation!?!? However even with settings for Pass-by-Value everywhere, using isolated loader-repositories in the jboss-app.xml's, trying java2ParentDelegation=false , ensuring Serializable and serialVersionUID set, etc. all it would give when I tried to cast the remote object retrieved via JNDI back into the original interface was the ClassCastException that I have now seen more times than I've had hot breakfasts. JBoss simply will not marshall/unmarshall the object as its passes between archives as it is supposed to.

              So I have had to relent and just package the WAR inside the original EAR, where the code instantly works (of course). JBoss classloader is hereby victorious over me... if I try tangling with that evil ba*#@rd classloader again I will involve a priest and copious amounts of holy water.

              • 4. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?

                There's only a few other things I can think of... The jboss-web.xml also allows loader-repository entries. I can't remember if I use this also, or I just use the wrapper ear to accomplish it. It's worth a try.

                The second item is, did you configure the UseJbossWebLoader entry in the Tomcat service.xml file? I believe that also plays a role in how classes get loaded for web applications.

                I left my laptop at home (the machine that has this configured), so I don't have the specifics right here with me.

                I feel your pain, I spent a lot of time getting my stuff working. And, I found a lot of posts in the forums that are just plain wrong IMO.

                Good luck,
                gary.

                • 5. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
                  xnuandax

                  Thanks Gary,

                  Did you get two co-located archives that contain the same interface classes to sing with 4.0.5 w/ EJB3 ?

                  I did run unique loader-repositories in the jboss-app.xml's, although I didn't play with UseJbossWebLoader this time around. I'm vaguely suspicious that Pass-by-Value isn't firing at all -- either I only got five out of the six places you need to request it, or it has foibles in the EJB3 config of 4.0.6....

                  Best,

                  David

                  • 6. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?

                    I am running 4.0.4GA with EJB3. Yes, I did get 2 archives running. And, I can hot-deploy either/both without issues (great for development).

                    Give the UseJbossWebLoader a try. I think that may be the missing link.

                    I don't think there is anything else I did. I'll poke around my laptop in the next day or two and see if there is anything else that I changed.

                    Let me know how you make out with the web loader change.
                    gary.

                    • 7. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
                      rikardf

                      Did you try to set "CallByValue" and "Isolated" to true in ear-deployer.xml?

                      • 8. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
                        skosonen

                         

                        I am running 4.0.4GA with EJB3. Yes, I did get 2 archives running. And, I can hot-deploy either/both without issues (great for development).


                        I also managed to develop my EJB3 & Web -application without this hot-deploy problem when using JBoss 4.0.4.GA. When I upgraded to 4.0.5.GA, I started having these problems.

                        For both versions I did the same configuration changes:
                        - Running JBoss with parameter "-Djava.rmi.server.hostname=localhost"
                        - jbossweb-tomcat55.sar/META-INF/jboss-service.xml: UseJBossWebLoader=true

                        I tried also changing the context.xml under Tomcat, but didn't help:
                        <antiJARLocking>true</antiJARLocking>
                        <antiResourceLocking>true</antiResourceLocking>
                        


                        I have one EAR-file that has EJB and WAR modules in it. If I make changes only in EJB module, package the EAR and deploy it, I get these ClassCastExceptions while trying to get session beans from servlets.

                        In JBoss 4.0.5.GA hot-deploy works when I make changes to both modules (EJB & WAR). This is the best workaround I have found on my problem. For separate EAR and WAR it might also work if both are redeployed?

                        It would be nice to find some better solution for this, though...


                        • 9. Re: JBoss Unified ClassLoader Hell? even with EJB3 ?
                          skosonen

                           

                          In JBoss 4.0.5.GA hot-deploy works when I make changes to both modules (EJB & WAR). This is the best workaround I have found on my problem. For separate EAR and WAR it might also work if both are redeployed?


                          Hmm... now this one is not working either. Quite tricky...