0 Replies Latest reply on Mar 1, 2004 8:43 AM by biondo79

    Set initial context

    biondo79 Newbie

      Hi! I´m a rookie on JBoss and I´would like to know the specific JNDI properties to set the InitialContext. I´m following the Titan Cruiser example. The JBoss EJB workbook doesn´t set anything, but at RunTime I got an exception:

      "javax.naming.NoInitialContextException: Need to specify class name in
      environment or system property, or as an applet parameter, or in an
      application resource file: java.naming.factory.initial"

      Is there any Java .property file that I need to configure? Here is the class code:

      package com.titan.cabin;


      import javax.naming.InitialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.util.Properties;
      import javax.rmi.PortableRemoteObject;

      public class Client_1 {
      public static void main(String[] args){
      try{
      Context jndiContext = getInitialContext();
      Object ref = jndiContext.lookup("CabinRemote");
      CabinHomeRemote home = (CabinHomeRemote) PortableRemoteObject.narrow(ref, CabinRemote.class);
      CabinRemote cabin_1 = home.create(new Integer(1));
      cabin_1.setName("Master Suite");
      cabin_1.setDeckLevel(1);
      cabin_1.setShipId(1);
      cabin_1.setBedCount(3);

      Integer pk = new Integer(1);

      CabinRemote cabin_2 = home.findByPrimaryKey(pk);
      System.out.println(cabin_2.getName());
      System.out.println(cabin_2.getDeckLevel());
      System.out.println(cabin_2.getShipId());
      System.out.println(cabin_2.getBedCount());

      }catch(RemoteException re){re.printStackTrace();}
      catch(NamingException ne){ne.printStackTrace();}
      catch(CreateException ce){ce.printStackTrace();}
      catch(FinderException fe){fe.printStackTrace();}
      }

      public static Context getInitialContext() throws NamingException{
      Properties p = new Properties();
      // Here is where my doubt is...
      return new InitialContext(p);
      }
      }