2 Replies Latest reply on May 8, 2002 7:25 AM by Amar

    JNDI Error

    Amar Newbie

      I have wrote an client application for my EJB "custbean"
      it is a BMP bean. My bean is successfully develoyed on JBOSS 2.4 .
      ------ Problem ------------

      When i run my client program with the command
      "java Test custbean" the following exception occurs

      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instan
      tiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClassInternal(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
      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 Test.main(Test.java:29)


      i am listing the deployment descriptor and my client program code
      please help me asap.

      thank you.
      ---------------
      the deployment descriptor for my bean is

      <ejb-jar>
      no description
      <display-name>Ejb2</display-name>
      <enterprise-beans>

      no description
      <display-name>custbean</display-name>
      <ejb-name>custbean</ejb-name>
      CustomerHome
      Customer
      <ejb-class>CustomerBeanVersion1</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False
      <env-entry>
      <env-entry-name>debug</env-entry-name>
      <env-entry-type>java.lang.Integer</env-entry-type>
      <env-entry-value>2</env-entry-value>
      </env-entry>
      <resource-ref>
      <res-ref-name>jdbc/bmp_properly</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </enterprise-beans>
      </ejb-jar>



      my client program is
      ~~~~~~~~~~~~~~~~~~~~
      public class Test
      {
      public static void main (String[] args) throws Exception
      {
      if (args.length != 1)
      {
      System.err.println ("Specify EJB JNDI name on command line");
      System.exit(-1);
      }

      System.setProperty("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.provider.url",
      "localhost:1099");

      String ejbName = args[0];

      Context c = new InitialContext();
      Object o = c.lookup (ejbName);
      CustomerHome h = (CustomerHome) PortableRemoteObject.narrow
      (o, CustomerHome.class);
      System.out.println ("Locating customer '1'");
      try
      {
      Customer customer = h.findByPrimaryKey ("1");
      System.out.println ("Customer exists: deleting");
      customer.remove();
      }
      catch (ObjectNotFoundException e)
      {
      System.out.println ("Customer does not exist");
      }
      System.out.println ("Creating customer 1");
      Customer customer = h.create ("1", "Kevin Boone", "Palmers Green, London", "kb@kevinboone.com");
      System.out.println ("Properties of new Customer EJB:");
      dumpCustomer (customer);
      System.out.println ("Finding Customer EJBs matching name `Boone'");
      Collection cc = h.findByNameContaining("Boone");
      Iterator customers = cc.iterator();
      while (customers.hasNext())
      {
      customer = (Customer)customers.next();
      System.out.println ("Found customer with ID " + customer.getId());
      }
      }

      // Dumps the properties of a Customer EJB
      public static void dumpCustomer (Customer customer) throws RemoteException
      {
      String customerId = customer.getId();
      String customerName = customer.getName();
      String customerAddress = customer.getAddress();
      String customerEmail = customer.getEmail();
      System.out.println ("id=" + customerId);
      System.out.println ("name=" + customerName);
      System.out.println ("address=" + customerAddress);
      System.out.println ("email=" + customerEmail);
      }
      }