title: Calling session Bean deployed on jboss 5.x from client side
body: <p>I'm running JBoss 5.1 GA with JDK 1.6 on Linux and trying to call session bean(jar containing this session bean is deployed on jboss server), Now i want to call this session bean from client, but didnt work.</p>
  
  <p>Java Code at client Side</p>
  
  <pre><code>public class CallingJbossSessionBeanFromClient {
  
  /**
   * @param args
   * @throws Exception 
   */
  public static void main(String[] args) throws Exception 
  {
      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "jnp://182.158.93.41:8080");
      Context context = new InitialContext(p);
      System.out.println("Successfully Lookup and going to call SessionBean Function deployed on JBoss-5.1.0 Server");
      SlsSessiongRemote remote=(SlsSessionRemote) context.lookup("SlsSessionBean/remote");
  //SlsSessionBean/remote is RemoteBinding of session Bean
      System.out.println("Called");
  }
  }
  </code></pre>
  
  <p>where 'SlsSessionBean/remote' is remote binding of session bean deployed on jboss server.
  @Stateless
  @RemoteBinding(jndiBinding="SlsSessionBean/remote")</p>
  
  <p>but end up with following error</p>
  
  <pre><code>Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
  at javax.naming.InitialContext.init(InitialContext.java:223)
  at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:197)
  at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:20)
       Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:247)
  at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
  ... 4 more
  </code></pre>
  
  <p>After seeing above error i added jbossjmx-ant.jar in the classpath of 'CallingJbossSessionBeanFromClient' class and got following error</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger
  at org.jnp.interfaces.NamingContext.&lt;clinit&gt;(NamingContext.java:181)
  at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:55)
  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
  at javax.naming.InitialContext.init(InitialContext.java:223)
  at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:197)
  at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:20)
      Caused by: java.lang.ClassNotFoundException: org.jboss.logging.Logger
  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
  ... 7 more
  </code></pre>
  
  <p>After seeing above error i added jboss-logging-spi.jar in the classpath of 'CallingJbossSessionBeanFromClient' class and got following error</p>
  
  <pre><code>Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: 182.158.93.41:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server /182.158.93.41:8080 [Root exception is java.io.EOFException]]
  at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763)
  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)
  at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
  at javax.naming.InitialContext.lookup(InitialContext.java:392)
  at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:22)
         Caused by: javax.naming.CommunicationException: Failed to retrieve stub from server /182.158.93.41:8080 [Root exception is java.io.EOFException]
  at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:327)
  at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734)
  ... 4 more
      Caused by: java.io.EOFException
  at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281)
  at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
  at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
  at java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:280)
  at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:312)
  ... 5 more
  </code></pre>
  
  <p>Plz tell me, am i on the right way to call sesion bean from client java class?
  I have spent hours looking for solution on Google. However I cannot seem to find anything that holds the hand..try to be more clear, i'm in lack of ideas in this problem, even it sounds like a classic 
  Plz suggest solution</p>