7 Replies Latest reply on Mar 7, 2008 6:22 PM by jgf1

    EJB3 deployment:Newbie question

    jgf1

      Hi folks.
      I am in process of reading Beginning Java EE 5 Platform by Apress and can't seem to get my application to run. I was wondering if anyone can shed some light for me. It appears to be some sort of binding issue.

      Directory Structure is:
      SimpleSessionApp
      beans
      client

      Code was compiled and run from SimpleSessionApp folder.

      Here's the same code

      package beans;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface SimpleSession
      {
       public String getEchoString(String clientString);
      }
      


      package beans;
      
      import javax.ejb.Stateless;
      
      @Stateless
      public class SimpleSessionBean implements SimpleSession {
       public String getEchoString(String clientString) {
       return clientString + " - from session bean";
       }
      }
      


      package client;
      
      import beans.SimpleSession;
      import javax.naming.InitialContext;
      
      public class SimpleSessionClient {
       public static void main(String[] args) throws Exception
       {
       InitialContext ctx = new InitialContext();
       SimpleSession simpleSession
       = (SimpleSession) ctx.lookup(SimpleSession.class.getName());
       for (int i = 0; i < args.length; i++) {
       String returnedString = simpleSession.getEchoString(args);
       System.out.println("sent string: " + args +
       ", received string: " + returnedString);
       }
       }
      }
      


      I've had to set up complicated classpath:
      c:\apps\jboss-4.2.2.ga\lib\concurrent.jar;
      c:\apps\jboss-4.2.2.ga\lib\jboss-common-jar;
      c:\apps\jboss-4.2.2.ga\client\jboss-j2ee.jar;
      c:\apps\jboss-4.2.2.ga\lib\commons-httpclient.jar;
      c:\apps\jboss-4.2.2.ga\server\all\lib\jboss.jar;
      c:\apps\jboss-4.2.2.ga\server\all\lib\jboss-remoting.jar;
      c:\apps\jboss-4.2.2.ga\server\all\lib\jboss-transaction.jar;
      c:\apps\jboss-4.2.2.ga\server\all\lib\jnpserver.jar;
      c:\apps\jboss-4.2.2.ga\server\all\deploy\ejb3.deployer\jboss-ejb3.jar;
      c:\apps\jboss-4.2.2.ga\server\all\lib\jboss-ejb3x.jar;
      c:\apps\jboss-4.2.2.ga\server\all\deploy\jboss-aop-jdk50.deployer\jboss-aop-jdk50.jar;
      c:\apps\jboss-4.2.2.ga\server\all\deploy\jboss-aop-jdk50.deployer\jboss-aspect-library-jdk50.jar;
      c:\apps\jboss-4.2.2.ga\client\jboss-common-client.jar;

      The last one was omitted from book, and had been giving a ClassNotFound exception for Logger. Found this on the net in another forum.

      But now, when I try and invoke program as follows:
      java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost client.SimpleSessionClient Now is the time for all good men

      I get the following error:

      Exception in thread "main" javax.naming.NameNotFoundException: beans.SimpleSession not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
      at sun.rmi.transport.Transport$1.run(Transport.java:159)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
      at java.lang.Thread.run(Thread.java:619)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at client.SimpleSessionClient.main(SimpleSessionClient.java:10)

      It's saying SimpleSession in package beans is not found.
      Is this some sort of JNDI lookup problem?


      Package was created as follows:
      jar cf SimpleSessionApp.ejb3 beans\*.java
      Copied SimpleSessionApp.ejb3 to server\all\deploy folder

      Any ideas?
      Cheers

        • 1. Re: EJB3 deployment:Newbie question
          jgf1

          I am sceptical about the jar command.
          I can normally view a jar file with Winzip.
          SimpleSessionApp.ejb3 is only 1K.
          When I attempt to open it, it appears to be empty.
          If you used annotations in your code should jar be automatically creating a deployment descriptor?
          How does it know how to format it correctly for JBoss?

          • 2. Re: EJB3 deployment:Newbie question
            jgf1

            Actually, I've confirmed ejb3 file did contain stuff.
            with jar -xf
            Also tried using *.* for jar command to pick up *.class & *.java.
            Also noticed status messages for JBoss
            18:49:15,718 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=SimpleSessionApp.ejb3,name=SimpleSessionBean,
            service=EJB3 with dependencies:
            18:49:15,859 INFO [EJBContainer] STARTED EJB: beans.SimpleSessionBean ejbName: SimpleSessionBean
            18:49:15,890 INFO [EJB3Deployer] Deployed: file:/C:/apps/jboss-4.2.2.GA/server/all/deploy/SimpleSessionApp.ejb3
            18:49:15,921 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/

            So is there some problem that JBoss has with doing JNDI lookups on Interface SimpleSession?
            If I was to do bind to SimpleSessionBean and cast this to Interface I think I might solve problem..
            But it begs the question why is the interface not available to bind to?

            • 3. Re: EJB3 deployment:Newbie question
              jgf1

              Looking int the JMX extensions I see the following:
              jar=SimpleSessionApp.ejb3,name=SimpleSessionBean,service=EJB3
              module=SimpleSessionApp.ejb3,service=EJB3

              So should I use SimpleSessionApp.ejb3
              as liternal to do JNDI lookup???

              • 4. Re: EJB3 deployment:Newbie question
                jgf1

                In case anyone else is reading this same book, I managed to get this working in the end.

                I found a very useful article here:
                http://www.adam-bien.com/roller/abien/entry/ejb_3_portability_issue_why

                When I changed the JNDI lookup to use the string "SimpleSessionBean/remote". I finally got the JNDI lookup to resolve.

                Then I came across another issue

                Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/security/SecurityAssociation

                I tracked this down to yet another missing jar in my classpath
                client/jbosssx-client.jar
                Hope this helps anyone else reading same material :)

                • 5. Re: EJB3 deployment:Newbie question
                  nishroop

                  Hi,
                  I have a similar kind of issue. But I am using EJB1.x.
                  You have mentioned that you changed the lookup string..So, have u changed the JNDI value in the xmls too?

                  • 6. Re: EJB3 deployment:Newbie question
                    jgf1

                     

                    "nishroop" wrote:
                    Hi,
                    I have a similar kind of issue. But I am using EJB1.x.
                    You have mentioned that you changed the lookup string..So, have u changed the JNDI value in the xmls too?

                    This example was just using session beans. No EJB's in sight.
                    With EJB3, there's a whole lot less XML to deal with if you use CMP.
                    Everything is done with annotations.
                    JNDI is still biting me though with another example I've tried with BMP (Here there was a lot of XML)
                    Check out the following:
                    CMP example:
                    http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4134654
                    BMP example:
                    http://www.jboss.com/index.html?module=bb&op=viewtopic&t=131432

                    • 7. Re: EJB3 deployment:Newbie question
                      jgf1

                       

                      "JGF1" wrote:
                      No EJB's in sight. I meant entity beans, which is where I take it most of your xml is coming from?