10 Replies Latest reply on Aug 15, 2012 2:27 PM by thiagodonadel

    Access EJB in .jar file

    thiagodonadel

      Hello,

       

      I'm using JBoss AS 7.1 and i'm trying to do this:

       

      I create a ,jar file with a ejb bean, so i put this jar in standalone/deployments and start JBOSS and this was printed in log :

       


      java:global/gesplanet-0.0.1/LoginService!br.com.gesplan.gesplanet.login.services.LoginService

      java:app/gesplanet-0.0.1/LoginService!br.com.gesplan.gesplanet.login.services.LoginService

      java:module/LoginService!br.com.gesplan.gesplanet.login.services.LoginService

      java:global/gesplanet-0.0.1/LoginService

      java:app/gesplanet-0.0.1/LoginService

      java:module/LoginService

       

      After that i create a war project tha use this ejb.  in war project i have the follow:

       

      @EJB(lookup="java:app/gesplanet-0.0.1/LoginService!br.com.gesplan.gesplanet.login.services.LoginService")

                LoginService service;

       

      but when i put the war file in standalone/deployments i get this:

       

      INFO  [org.jboss.weld.ClassLoading] (MSC service thread 1-4) catching: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class br.com.gesplan.war.ejbtest.TesteEjb

                at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:152) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:86) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:115) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:171) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:336) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.weld.services.WeldService.start(WeldService.java:76) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0]

                at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0]

      Caused by: java.lang.NoClassDefFoundError: Lbr/com/gesplan/gesplanet/login/services/LoginService;

                at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.7.0]

                at java.lang.Class.privateGetDeclaredFields(Class.java:2308) [rt.jar:1.7.0]

                at java.lang.Class.getDeclaredFields(Class.java:1760) [rt.jar:1.7.0]

                at org.jboss.weld.util.reflection.SecureReflections$4.work(SecureReflections.java:102) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.util.reflection.SecureReflections$4.work(SecureReflections.java:99) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.runAndWrap(SecureReflectionAccess.java:63) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.util.reflection.SecureReflections.getDeclaredFields(SecureReflections.java:99) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:153) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:118) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:49) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:40) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355)

                at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)

                at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)

                at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)

                at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393)

                at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:149) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                ... 11 more

      Caused by: java.lang.ClassNotFoundException: br.com.gesplan.gesplanet.login.services.LoginService from [Module "deployment.WAR2-1.0.war:main" from Service Module Loader]

                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

                ... 29 more

       

      So, i want to know how make this work.

       

      If someone can help me!

       

      Thanks.

        • 1. Re: Access EJB in .jar file
          ctomc

          hi,

           

          bundle ejb-jar inside of your war file instead of separete deployment . this is possible since JEE6.

           

           

          --

          tomaz

          • 2. Re: Access EJB in .jar file
            thiagodonadel

            Ok, but i don't want put the jar inside of the war. I want to keep them separated.

            How i can do that ?

            • 3. Re: Access EJB in .jar file
              jaysensharma

              Hi Thiago,

               

                  Try the following lookup:

               

               

              @EJB(lookup="java:global/gesplanet-0.0.1/LoginService!br.com.gesplan.gesplanet.login.services.LoginService")

                        LoginService service;

               

               

              Example:  http://middlewaremagic.com/jboss/?p=822

               

              The above link demonstrates how to lookup Local EJB3 stateless Bean from a separate Web Application’s Servlet. Where as the EAR containing the Stateless EJB3 and the WAR are separately deployed on the same JBoss AS7 instance.

              1 of 1 people found this helpful
              • 4. Re: Access EJB in .jar file
                sfcoy

                If you want to keep them separate then you will have to grok Class Loading in AS7.

                 

                Really, it's easier to put it in the war file. You can even put the classes directly in the war file if that makes it any easier.

                • 5. Re: Access EJB in .jar file
                  cfang

                  You can package the ejb jar and war in the same EAR, include all common classes and interface classes in EAR/lib/x.jar, and inject the bean into servlet class with @EJB().  Typically you don't need any attribute for @EJB, if there is only one bean class implementing that business interface.

                   

                  If you have to deploy them as separate deployment units, then the easiest way is to include all common classes in both archives, and inject with @EJB(lookup="java:global/..")

                  • 6. Re: Access EJB in .jar file
                    thiagodonadel

                    Ok.

                     

                    I try a lot deploy them separate but i always get the same error. so i have package the ejb and the war in the same EAR.

                    But, imagine i have one war file and and a lot of "ejb jar" in the same ejb. If i want change one ejb i will need re-deploy the ear right ? 

                    What i want to do is change one ejb whitout re-deploy the others, but to do that i need separate them...

                    • 7. Re: Access EJB in .jar file
                      cfang

                      did you package EJB business interface classes in both the ejb jar and war?  Double check with jar tvf WAR2-1.0.war.  The error indicates the interfaces are not available to war.

                      1 of 1 people found this helpful
                      • 8. Re: Access EJB in .jar file
                        thiagodonadel

                        Did you mean this interface ?

                         

                        @Remote

                        public interface LoginServiceRemote {

                         

                                  public boolean checkUser(String login, String password);

                         

                         

                        }

                         

                        this class is only in ejb jar. 

                        • 9. Re: Access EJB in .jar file
                          cfang

                          Any business interfaces referenced by your web app should be packaged in your web app, as well as their implementation ejb jar.  If LoginServiceRemote is the interface exposed to the servlet client, then it should be like:

                           

                          @EJB(lookup="...")

                                    LoginServiceRemote service;

                          • 10. Re: Access EJB in .jar file
                            thiagodonadel

                            i put and work !!!!!!!!!!!!!!

                             

                            thanks very much!!!!!!!!!!!!!!!!!!!!!!!!