3 Replies Latest reply on Jul 9, 2009 10:57 PM by coldgin

    How to load Seam component from JAR file

    coldgin

      Hi. I have an annotated Seam session bean that I want to externalize from my current Seam application, and package it into a reusable .jar file. When I package the component inside a secondary jar file, add that jar file as an EJB module to my application.xml, and package the jar file inside of the .ear file, the component is not found.


      After reading a little bit, I am wondering if this has to do with the jndiPattern in my components.xml file? All of the seam components that are packaged within SeamApp.jar are detected and loaded. The seam component in Utility.jar is not. Below is the project structure, annotated classes, and relevant config. Any idea how I can load the seam component from Utility.jar? Any other settings that I am missing?


      Thank you.


      Project packaging:


      SeamApp.ear
      ---SeamApp.jar
      ---Utility.jar
      ---SeamApp.war



      application.xml:


         <module>
            <web>
               <web-uri>SeamApp.war</web-uri>
               <context-root>/SeamApp</context-root>
            </web>
         </module>
      
         <module>
            <ejb>Utility.jar</ejb>
         </module>
        
         <module>
            <ejb>SeamApp.jar</ejb>
         </module>
         
         <!-- Seam and EL -->
         
         <module>
             <ejb>jboss-seam.jar</ejb>
         </module>



      components.xml jndiPattern value is:




      SeamApp/#{ejbName}/local





      Annotated classes that are packaged in Utility.jar:


      @Local
      public interface TestController 
      {
              public String testMe();
      }
      
      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("testComponent")
      public class TestManager implements TestController
      {
              @In 
              Identity identity;                                      // Identity of logged in user
              
              @Logger
              private Log log;
              
              /**
               * Default constructor
               */
              public TestManager()
              {
                      log.info("**** TEST COMPONENT FROM EXTERNAL JAR -> CTOR CALLED ****");
              }
      
              /**
           * This method is for testing only
           * 
           * @return String
           */
          public String testMe()
          {
              log.info("**** TEST COMPONENT LOADED FROM EXTERNAL JAR ****");
              
              return "hello from test component";
              }
      }







        • 1. Re: How to load Seam component from JAR file
          barakka

          Hi,


          have you included a seam.properties (possibly empty) in your utility jar file? Without it, seam won't recognize the jar as containing seam components and won't scan it.


          Hope it helps,
          Riccardo.

          • 2. Re: How to load Seam component from JAR file
            coldgin

            Thank you very much, Riccardo. After adding seam.properties to the JAR file, it found the seam component, but the injected @Logger and @Identity instances are null inside that component, giving me a NullPointerException when the testMe method is called from the page.


            This only happens with the seam component that is loaded from Utility.jar.


            I removed the log.info call from the constructor of TestManager also. I errors out with an NPE on the log.info() call inside testMe().

            • 3. Re: How to load Seam component from JAR file
              coldgin

              OK - Got it. I added a META-INF folder to my JAR file, and copied the ejb-jar.xml file from my original Seam jar into my Utility.jar file. This was the key to getting the dependency injection working, as you can see that there are references to the SeamInterceptor classes inside ejb-jar.xml.


              Thanks to Riccardo's response, the approach that led to the final solution was simply comparing the SeamApp.jar file contents to the Utility.jar contents.


              Riccardo - Thanks again, man.