8 Replies Latest reply on May 19, 2003 6:23 AM by pstrotmann

    EJB client error

    substring Newbie

      Hello All,

      All I am trying to do is to work thru a very simple EJB program to learn the EJB structure. But apparently, it is harder than I thought. It seems all the "simple" EJB examples I found on the Net turn out to be not that simple... at least to a newbie like me.

      Okay, I am working on this "simple" EJB project that does not use struts, does not use ant. Just compile and build on the command prompt. The deployment of the jar file to JBoss was successful according to the message displayed on JBoss console. Then there is a simple client class for testing purpose. This client class is compiled and then run in its project folder.

      When I run the client class, I got error message as followed:
      //message begin-----------------------------------------------
      C:\workspace>java -classpath c:\JBoss-3.2.1_tomcat-4.1.24\client\jboss-client.jar;c:\jboss-3.2.1_tomcat-4.1.24\client\jnp-client.jar;. Client "argument"
      Exception in thread "main" java.lang.NoClassDefFoundError: javax/net/SocketFactory
      at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:41)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      at Client.main(Client.java:25)
      //message end-----------------------------------------------

      In the main of Client.java, I have these lines of code:
      //code begin-----------------------------------------------
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      //code end-----------------------------------------------

      Then if I add jnet.jar to the classpath, I got a different but similar error message:
      //message begin---------------------------------------
      C:\workspace>java -classpath c:\JBoss-3.2.1_tomcat-4.1.24\cl
      ient\jboss-client.jar;c:\jboss-3.2.1_tomcat-4.1.24\client\jnp-client.jar;c:\jboss-3.2.1_tomcat-4.1.24\client\jnet.jar;. Client "argument"
      Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger
      at org.jnp.interfaces.NamingContext.(NamingContext.java:103)
      at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:41)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      at Client.main(Client.java:25)
      //message end--------------------------------------------------

      It is getting to be very frustrating. Please help. Thank you very much.

        • 1. Re: EJB client error
          Jon Barnett Master

          Try these in your classpath as I can't remember which ones you absolutely need, but you can get it working first and then experiment with removing libraries from the classpath later:
          jboss-client.jar, jboss-common-client.jar, jboss-j2ee.jar, jbosssx-client.jar, jboss-transaction-client.jar, jnp-client.jar and log4j.jar - these should be from the client directory of your JBoss distribution.

          Next, since you are running a remote-client (it is not running in the same JVM as JBoss), you will need to connect over the wire. So your properties configuration is going to require this:
          properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
          properties.put("java.naming.provider.url","jnp://localhost:1099");
          properties.put("java.naming.factory.url.pkgs","org.jboss.naming");

          If your remote client is not on the same server, you will need to change the jnp://localhost:1099 to the appropriate URL to locate the JNDI port for your JBoss server.

          • 2. Re: EJB client error
            substring Newbie

            Hey, it works!!! Thank you very much, jonlee, for your help.

            Now, for the sake of learning, please allow me to ask this question: What are the differences between my original code and the code that you provided (i.e. your 3 lines of "properties.put")?

            //original code begin--------------------------------
            properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            properties.put(Context.PROVIDER_URL, "localhost:1099");
            //original code end----------------------------------

            With the original code, and after I added all the jar files to the classpath, the client application can get the initial context. But when it comes to getting a reference to the bean, it gets error message as followed:
            //message begin-------------------------------------
            log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
            log4j:WARN Please initialize the log4j system properly.
            javax.naming.CommunicationException: Receive timed out [Root exception is java.io.InterruptedIOException: Receive timed out]
            //message end-------------------------------------

            Please explain. Again, thank you very much for your help.

            • 3. Re: EJB client error
              substring Newbie

              It works!!! Thank you very much, jonlee, for your help.

              Now, for the sake of learning, please allow me to ask this question: What are the differences between my original lines of code and the 3 lines of code that you provided (i.e. "the properties.put...")?

              //original code begin------------------------------------
              properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              properties.put(Context.PROVIDER_URL, "localhost:1099");
              //original code end------------------------------------

              With the original code, and after I add all the jar files to the classpath, the client application can get the initial context. But when it comes to getting the reference to the bean, it gets the following error message:
              //message begin------------------------------------------
              log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
              log4j:WARN Please initialize the log4j system properly.
              javax.naming.CommunicationException: Receive timed out [Root exception is java.io.InterruptedIOException: Receive timed out]
              //message end------------------------------------------

              Please explain. Again, thank you very much for your help.

              • 4. Re: EJB client error
                substring Newbie

                Testing, testing.

                For some unknown reasons, I cannot post this morning.

                • 5. Re: EJB client error
                  Hussein Badakhchani Newbie

                  Hello,

                  I found all the classes my client needs are in the jbossall-client.jar found under JBOSS_HOME/client

                  Hoos

                  • 6. Re: EJB client error
                    Jon Barnett Master

                    There are two properties that control the use of and access to the JBoss JNDI provider. Even in JBoss, these are set so that EJBs can find other EJBs and JNDI registered resources in the JBoss JNDI service. Have a look at jndi.properties in the server/instance/conf directory. You'll see it has these defined:
                    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

                    It comments out the provider URL. When components are running in the same JVM as the JNDI provider, you don't need to generate an RMI connection to the JNDI provider. So if you were running a web application in Jetty, which is itself a service in JBoss, then web application components are running in the same VM as the JBoss JNDI. So you don't need to specify the provider URL - it expects to find the directory locally, so to speak.

                    However, if you were running a web application in Jetty that is not a service in JBoss - i.e. You are running a standalone Jetty, even if it is on the same machine, then you need that last line to connect to the JNDI service.

                    So if you were running a client from the command line to use EJBs in JBoss, you would be running a separate Java VM and you would need to tell that client how to physically connect to the JNDI service (IP address and port).

                    I'm not sure about your last problem. Is your JDK or JBoss installed in a path that contains spaces? There is an RMI problem with the JDK that can cause issues related to searching the JNDI.

                    Also ensure you do have the log4j.jar in the classpath of the client.

                    • 7. Re: EJB client error
                      pstrotmann Newbie

                      Hi JonLee

                      it seems my problem is a similiar one to the already solved client
                      access problem:

                      gp-client:
                      [gp] GpClient started
                      [gp] new InitialContext() successful
                      [gp] jndi.lookup('gp/Adresse') not successful
                      [gp] null
                      [gp] javax.naming.CommunicationException. Root exception is java.lang.ClassNotFoundException: org.jboss.ejb.plugins.local.LocalHomeProxy (no security manager: RMI class loader disabled)

                      Adresse is an EntitiyBean, jndi.lookup to sessionBeans works fine.

                      I tried to find the missing class in the listed jars, but failed.

                      peter

                      ps. :
                      jndi.lookup('gp/Adresse') works fine, when I use the JUNIT-Framework,

                      • 8. Re: EJB client error
                        pstrotmann Newbie

                        self reply:

                        After some experimentation I found out that the following ant construct works:

















                        simply speaking I included everything jboss offers, but I'm working to get some more granularity. ${jboss.home}/server/default/lib seems to contain org.jboss.ejb.plugins.local.LocalHomeProxy.

                        peter