14 Replies Latest reply on Nov 30, 2011 9:01 AM by Prasad Deshpande

    Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException

    Aleš Bregar Newbie

      Hi,

       

      I think I am close to finish my tryout to migrate as 4.2.3 app to as7. (App was designed as multiple ears, each comprising ejb and war).

      But the following problem so far I am unable to solve.

       

      Business logic usage among multiple ears was designed by using @Remote interfaces on SLSB. Putting an @EJB annotation provided access to the proxy of bean impl. Now trying to do the same with as7.1.BETA1 throws

       

       

      ...
      Caused by: java.lang.NoClassDefFoundError: Lcom/acme/test/ejbremote_core/services/HelloService;
              at java.lang.Class.getDeclaredFields0(Native Method) [:1.6.0_29]
              at java.lang.Class.privateGetDeclaredFields(Class.java:2291) [:1.6.0_29]
              at java.lang.Class.getDeclaredFields(Class.java:1743) [:1.6.0_29]
              at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.0.Beta1.jar:]
              at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.0.Beta1.jar:]
              ... 10 more
      Caused by: java.lang.ClassNotFoundException: com.acme.test.ejbremote_core.services.HelloService from [Module "deployment.ejbremote-ear.ear.ejbremote-ejb-0.0.1-SNAPSHOT.jar:main"
       from Service Module Loader]
      ...
      

       

       

      If I try to do the same by Initialcontext lookup I can see that object is found in the JNDI space but the problem is I cannot cast it to proper class as it throws ClassCastEx.

       

      I have checked on issues AS7-1658 and AS7-423 and also check the related discussions here. Have not yet digged deeper to docs on classloading mechanism in as7. But still had not figgured out how is the desired behaviour on topic.

       

      I would appreciate a hint if this should work and how (or what am I missing here ...).

       

      Thank you in advance,

      K

        • 1. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
          Stephen Coy Master

          Each EAR needs it's own copy of the remote interface classes used to access EJBs in the other EAR. Is that the case now?

          • 2. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
            Aleš Bregar Newbie

            Well, no.

             

            Have tried that, but if I put same @Remote annotated interface to both EARs following occurs:

             

            11:13:40,609 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.subunit."ejbremote-ear.ear"."ejbremote-ejb-0.0.1-SNAPSHO
            T.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."ejbremote-ear.ear"."ejbremote-ejb-0.0.1-SNAPSHOT.jar".INSTALL: Failed to process phase INS
            TALL of subdeployment "ejbremote-ejb-0.0.1-SNAPSHOT.jar" of deployment "ejbremote-ear.ear"
                    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.1.0.Beta1.jar:]
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:]
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_29]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_29]
                    at java.lang.Thread.run(Thread.java:662) [:1.6.0_29]
            Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011058: Failed to install component HelloWorldServiceBean
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:95)
                    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.Beta1.jar:]
                    ... 5 more
            Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: No component found for type 'com.acme.test.ejbremote_core.services.HelloService' with name null for
            binding com.acme.test.ejbremote.services.HelloWorldServiceBean/hs
                    at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:77)
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:240)
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access$000(ComponentInstallProcessor.java:74)
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.handle(ComponentInstallProcessor.java:194)
                    at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:190)
                    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:93)
                    ... 6 more
            

             

            Any other idea?

            • 3. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
              Prasad Deshpande Expert

              How have you packaged your remote interfaces jar? does that contain just interfaces or other classes (Bean/POJO) too? As Steve said earlier, you'll need remote interface(s) copy in the EAR where you are accessing this bean. It might be that you'll have to rebundle you remote interfaces jar for the use in other EAR(s).

               

              If you say the you have included ejbremote-ejb-0.0.1-SNAPSHOT.jar in other ear, looking at above error, it seems that above jar contains bean class as well, which is what it's trying to deploy. You just need interfaces jar.

               

              How is your packaging btw?

              • 4. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                Aleš Bregar Newbie

                I would be glad if one of you please check the attached eclipse projects:

                - 'ejbremote_core' has HelloService @Remote interface and bean impl

                - 'ejbremote' tries to use the HelloService as @EJB with above errors

                 

                (while I am not yet maven expert, I did maually put HelloService interface to various places inside ejbremote ear with no success)

                 

                Thank you in advance for looking into this.

                • 5. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                  Ales Justin Master

                  As a side note, you could extract interfaces jar into separate deployment, and have both .ears depened on that module.

                  (AS7 has strict modular classloading, while AS4 (actually any pre-v7) had global view (unless specified diff) of deployment's classes / resources)

                  • 6. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                    Aleš Bregar Newbie

                    Tnx for joining in Ales.

                     

                    Ok, tried what you proposed:

                    - created separate jar 'ejbremote-core-ejbapi-0.0.1-SNAPSHOT.jar' with both ear's remote interfaces

                    - altered both ears ejbs MANIFEST.MF with 'Dependencies: org.apache.log4j,deployment.ejbremote-core-ejbapi-0.0.1-SNAPSHOT.jar'

                    - removed interfaces from both ejbs

                     

                    Result:

                    - ear 'ejbremote_core' deployed with success

                    - ear 'ejbremote' failed again with

                     

                    16:34:39,466 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "ejbremote-ear.ear"
                    16:34:39,566 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "ejbremote-ejb-0.0.1-SNAPSHOT.jar"
                    16:34:39,587 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class com.acme.ejbremote.services.AlohaServiceBean in Module "deployment.ejbremote-ear.ear.ejbremot
                    e-ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/acme/ejbremote/services/AlohaServiceBean (Module "deployment.ejbremote-ear.ear
                    .ejbremote-ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader)
                            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:416) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:260) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.Module.loadModuleClass(Module.java:500) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:485) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:421) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:143) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:111)
                            at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:54)
                            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.Beta1.jar:]
                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:]
                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:]
                            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_29]
                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_29]
                            at java.lang.Thread.run(Thread.java:662) [:1.6.0_29]
                    Caused by: java.lang.NoClassDefFoundError: com/acme/ejbremote/services/AlohaService
                            at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_29]
                            at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_29]
                            at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_29]
                            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_29]
                            at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:330) [jboss-modules.jar:1.1.0.CR4]
                            at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:411) [jboss-modules.jar:1.1.0.CR4]
                            ... 15 more
                    

                     

                    any idea?

                    • 7. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                      Prasad Deshpande Expert

                      could you please attach both your ear's from above projects? I'm having trouble at the moment with my eclipse workspace to build it myself...

                      • 8. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                        Aleš Bregar Newbie

                        Sure, attached right now.

                         

                        Have played a little more (by trial/failure) to get some clue, but whatever combination of files, i got 'NoClassDefFoundError' or 'DeploymentUnitProcessingException: No component found for type....'

                         

                        thank you for looking into this.

                        • 9. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                          Ales Justin Master

                          Ok, tried what you proposed:

                          - created separate jar 'ejbremote-core-ejbapi-0.0.1-SNAPSHOT.jar' with both ear's remote interfaces

                          - altered both ears ejbs MANIFEST.MF with 'Dependencies: org.apache.log4j,deployment.ejbremote-core-ejbapi-0.0.1-SNAPSHOT.jar'

                          - removed interfaces from both ejbs

                           

                          Result:

                          - ear 'ejbremote_core' deployed with success

                          - ear 'ejbremote' failed again with

                           

                          any idea?

                          Hmmm, this should work.

                          Are you sure the MANIFEST.MF still has that dependency?

                          As I've sometimes seen this being overridden by build tools, IDE, ...

                          • 10. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                            Stephen Coy Master
                            1. Technically I think these EAR files should fail to deploy as you have specified J2EE 1.4 deployment descriptors for them, and they contain EJB 3.0 ejb jars. (This was a JBoss 4.x extension)
                            2. As I mentioned above, your ejb-remote ear needs an additional jar file containing the HelloService interface class. Classes in the  ejb-remote ear cannot access the classes in the ejb-remote-core ear. This again could be considered to be a JBoss 4.x extension

                             

                            You (and probably a lot of other migrators from earlier JBoss implementations) will find it helpful to become familiar with the "Class Loading Requirements" section (8.3) of the JEE 6 Platform Specification.

                            • 11. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                              Stephen Coy Master

                              The attached version of your project deloys and runs on JBoss 7.1.0.Beta1

                              2 of 2 people found this helpful
                              • 12. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                                Aleš Bregar Newbie

                                @Stephen

                                 

                                Thank you very much for the time on that, that does actually work and I will go for it in my migration task.

                                 

                                @Ales

                                 

                                But still I would like to see the 'Dependency' in the MANIFEST.MF to properly propagate the value from common jar deployment. I have double checked and packaging tool didn't drop the line from manifest.mf as I have manually added it afterwards.

                                And I would be very glad if you have time to check the test case to confirm the issue on that (as you state that this should work).

                                 

                                 

                                 

                                Thanks again to all for the helpful replies.

                                • 13. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                                  Aleš Bregar Newbie

                                  And another simplification if possible. Currently, there is a need to have an explicit defined lookup

                                   

                                   

                                  @EJB(lookup="java:global/ejbremote-core-ear/ejbremote-core-ejb/HelloServiceBean")
                                      HelloService hs;
                                  

                                   

                                   

                                  Do you see any possibility to go for plain @EJB (or @Inject) if possible, without explicit lookup defined (as it is more clean code IMO, but can live with it for now)

                                  • 14. Re: Two Different EARs(same JVM), looking each other ejb's throws ClassNotFoundException
                                    Prasad Deshpande Expert

                                    kristjan slomsek wrote:

                                     

                                    Do you see any possibility to go for plain @EJB (or @Inject) if possible, without explicit lookup defined (as it is more clean code IMO, but can live with it for now)

                                    If you want to inject inside a servlet/EJB within same app (ear),

                                    @EJB HelloService hs;

                                    would still work (unless your EJB implements more than 1 interface).  Otherwise, you'll need to provide JNDI name if lookup is from another app within same JVM. However, if this is done from a managed bean, I'm sure I read somewhere that it was a bug in AS 7.0.2 where it was not injecting EJB just with @EJB annotation.