3 Replies Latest reply on Nov 6, 2005 9:35 AM by myawn

    No luck getting embedded deployment to work

    myawn

      I've tried several different variations on the code shown in the tutorials (deploy by resource, deploy by directory) and I can't get my classes to deploy in an embedded fashion.

      I did try packing the classes into a EJB3 jar and deploying them in the application server, and doing so gave me some useful diagnostics (deployment failures) that helped me debug the classes. I was hoping that once they deployed cleanly in the AS, they would also deploy embedded, but it seems my embedded problem must be something different.

      One thing I'm doing which is different than any of the examples is I am not packaging the classes (no .jar, .ejb3, or .ear is built); I'm trying to just run out of the directory hierarchy within an Eclipse environment. This leads to one question, which is where should persistence.xml go in this case? I found that I was getting NullPointerExceptions from EJBStandaloneDeployer if I just put the persistence.xml in with the classes. I looked at the source for that class and noticed that the META-INF directory is hard-coded in the persistence.xml lookup. So I placed persistence.xml within a META-INF directory within the resources directory, and the exception went away -- so I think the file is being found now.


      I've gone through a lot of permulations of this, but here is what I'm currently using as my 'main' entry point:

      /** Test class for EJB 3.0 beans. */
      public class EJB30Main {
      
       public static void main(String[] args) throws Exception {
      
       System.out.println("main loading deployer");
      
       EJB3StandaloneBootstrap.boot(null);
       EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer();
      
       try {
       URL wsdldir = new URL("file:///C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/com/kenai/examine/wsdl");
       URL resdir = new URL("file:///C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/resources");
       deployer.getDeployDirs().add(wsdldir);
       deployer.getDeployDirs().add(resdir);
       System.out.println("Deploy dirs " + deployer.getDeployDirs());
      
       deployer.setJndiProperties(getInitialContextProperties());
       deployer.create();
       deployer.start();
       System.out.println("deployer running");
       } catch (Exception e) {
       e.printStackTrace();
       deployer.stop();
       deployer.destroy();
       }
      
       WSDLMgr mgr = WSDLMgr.getInstance();
       String urlLoc = "http://keithsvr1/UnitTestWS1/Service1.asmx?wsdl";
       String wsdlName = "j2eePersistenceTest";
       WSDL wsdl = mgr.create(wsdlName, urlLoc);
       System.out.println("Created " + wsdl.getName() + " " + wsdl.getID());
      
       System.out.println("Stopping and destroying deployer");
       deployer.stop();
       deployer.destroy();
       System.out.println("Normal finish");
      
       }
      
       private static Hashtable getInitialContextProperties() {
       Hashtable<String,String> props = new Hashtable<String,String>();
       props.put("java.naming.factory.initial",
       "org.jnp.interfaces.LocalOnlyContextFactory");
       props.put("java.naming.factory.url.pkgs",
       "org.jboss.naming:org.jnp.interfaces");
       return props;
       }
      }
      


      And here is what is currently in persistence.xml
      <entity-manager>
       <name>manager1</name>
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <class>com.kenai.examine.wsdl.WSDL</class>
       <class>com.kenai.examine.database.SharedDBInfo</class>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       </properties>
      </entity-manager>
      


      (I've tried with and without the class names, makes no difference).

      When I attempt to run the main, here's all I get:
      main loading deployer
      WARN 01-11 07:33:43,568 (XsdBinder.java:bindGlobalGroup:1097) -NOT HANDLED WILDCARD IN GLOBAL MODEL GROUP
      Deploy dirs [file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/com/kenai/examine/wsdl, file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/resources]
      deployer running
      Exception in thread "main" java.lang.NullPointerException
       at com.kenai.examine.wsdl.WSDLMgr.create(WSDLMgr.java:269)
       at com.kenai.examine.wsdl.WSDLMgr.create(WSDLMgr.java:218)
       at com.kenai.examine.wsdl.EJB30Main.main(EJB30Main.java:69)
      


      Within WSDLMgr, I have the following declaration of the EntityManager

       @PersistenceContext(name="manager1")
       public void setEntityManager(EntityManager em) {
       System.out.println("EM injected");
       this.em = em;
       }
      


      And the line that fails is a call to em.persist(wsdl) -- so the null pointer, plus the lack of output from the method above, show that we aren't ever injecting the entity manager reference.

      The WSDLMgr class is annotated as a Stateless Session Bean. Instead of calling getInstance() on it, I also tried making an @EJB reference within the main class (which I think it the preferred way to do it) -- but then that reference is never injected, so I don't even get as far as I did before.


      Can anyone point out what I'm doing wrong here? Thanks!

      Mike



        • 1. Re: No luck getting embedded deployment to work
          bill.burke

          what does WSDLMgr.getInstance() look like?

          You need lookup stateless session beans in JNDI. Also, injection on the static main class will not work either.

          Also, check out the scanClasspath() method on EJB3StandaloneBootstrap. It is a much easier way of deployment.

          Let me know how it goes.

          • 2. Re: No luck getting embedded deployment to work
            myawn

            WSDLMgr.getInstance() was just getting a reference to the singleton instance of the class, which is how this all worked in a J2SE configuration.

            I've replaced that call with a JNDI lookup by the local interface name.

            But it looks like I'm still not getting deployed, either when I specify the directory where the class lives, or when I try the scanclasspath (which looks like a nice way to test, but will be too slow for us to use in a live app).

            Here's what I see from the scanclasspath version:

            main loading deployer
            WARN 03-11 08:08:31,100 (XsdBinder.java:bindGlobalGroup:1097) -NOT HANDLED WILDCARD IN GLOBAL MODEL GROUP
            Scanning for EJBs to deploy
            Classpath scanning took 12827 ms
            Exception in thread "main" java.lang.NoSuchMethodError: org.jboss.aop.joinpoint.MethodInvocation.<init>(Lorg/jboss/aop/MethodInfo;[Lorg/jboss/aop/advice/Interceptor;)V
             at org.jboss.ejb3.EJBContainerInvocation.<init>(EJBContainerInvocation.java:28)
             at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:143)
             at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:60)
             at $Proxy17.create(Unknown Source)
             at com.kenai.examine.wsdl.EJB30Main.main(EJB30Main.java:94)
            


            Now I'm not doing anything with AOP, so there aren't any interceptor classes to be found -- but maybe that message really indicates that my class hasn't been deployed at all.

            The failure is on the mgr.create() call, which indicates that the JNDI lookup succeeded. When specifying directories to search, I don't get that far and fail on the lookup with:

            deployer running
            Exception in thread "main" javax.naming.NameNotFoundException: com.kenai.examine.wsdl.WSDLMgrLocal not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:516)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:524)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:530)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
             at javax.naming.InitialContext.lookup(Unknown Source)
             at com.kenai.examine.wsdl.EJB30Main.main(EJB30Main.java:84)
            


            I'm still a little fuzzy on exactly what paths to feed in to the deployer here; All of my annotated classes and interfaces are in a single directory, so passing that directory name is obvious. But for persistence.xml, if I pass a URL that points to the persistence.xml file, I get a NullPointerException as shown here:

            Deploy dirs [file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/com/kenai/examine/wsdl, file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/resources, file:/C:/Documents%20and%20Settings/myawn/j2ee/com.kenai.examine/bin/resources/META-INF/persistence.xml]
            java.lang.NullPointerException
             at org.jboss.ejb3.embedded.EJB3StandaloneDeployer.create(EJB3StandaloneDeployer.java:336)
            


            I don't get the exception if I just point to the 'resources' directory. I'm hoping in that case that it's finding resources/META-INF/persistence.xml, but I don't see any messages confirming that the file was read (I do see some message confirming that when I deploy in the AS, but perhaps the standalone deployer is just less verbose)


            To summarize
            - if I try to specify deploy directories, I fail when I try to lookup the bean
            - if I use scanclasspath, I fail when I try to call a method on the bean

            I realize I haven't posted my bean source; I can do that, but in the interest of brevity I'lll hold off until/unless someone asks to see that. The essentials are:

            - there is a local interface and a remote interface. They are annotated with @Local and @Remote, respectively, and have no other annotations.

            - the Entity bean class is pretty straightforward, with @Entity, @Table, @Column, @Id, @Transient annotations.

            - the manager class (which is where the problem seems to lie) has a @Stateless annotation, and a @PersistenceContext annotation (with no unitName) on the setEntityManager method.

            I have a feeling this is really close, and there's just some simple requirement that I've failed to meet (I just tried changing the no-arg constructor on the class from private to public, for example, but that didn't do the trice).

            Thanks for the pointers so far

            Mike

            • 3. NoSuchMethodError on org.jboss.aop.joinpoint.MethodInvocatio
              myawn

              I'm making progress, but not quite there yet.

              I've gotten my deploy directories straightened out so that the EJBStandaloneDeployer finds my bean classes, either with a scanclasspath() (convenient but not fast enough) or by specifying the directories directly. And the JNDI lookups are working in either case.

              But I can't invoke a business method of the bean without getting the following error (reported in my last post, also):

              xception in thread "main" java.lang.NoSuchMethodError: org.jboss.aop.joinpoint.MethodInvocation.<init>(Lorg/jboss/aop/MethodInfo;[Lorg/jboss/aop/advice/Interceptor;)V
               at org.jboss.ejb3.EJBContainerInvocation.<init>(EJBContainerInvocation.java:28)
               at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:143)
               at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:60)
               at $Proxy17.create(Unknown Source)
               at com.kenai.examine.wsdl.EJB30Main.main(EJB30Main.java:84)
              


              I found a few threads that mentioned this error message, but they were in a client/server configuration, not embedded, and it appears the issue was resolved by adding one or more client-side directories to the server classpath. I don't think that's my problem here; the class org.jboss.aop.joinpoint.MethodInvocation is in jboss-aop-jdk50.jar, and I've verified that that library is on my run-time classpath. (I didn't go so far as to try to verify that there is a constructor with the specified signature in that class, so I suppose it's possible that I have a class version problem -- but since all the jar files came from the same distribution, that seems unlikely)

              My runtime classpath includes all .jar files found in \jboss-EJB-3.0_Embeddable_ALPHA_3\lib, plus the \conf directory. Is anything else needed?

              Mike