NoInitialContext while running Client_41a of Workbook 2
opapo Dec 17, 2004 4:56 PMI am using:
JBoss AS 4.0
Eclipse 3.0
Ant 1.6.2
I went through workbook 2 at the end of the book. I tried to use the command ant run.client_41a and it compiled and deployed the EJB files. I used ant asdf and it did the same thing. I used ant no difference.
I decided to use Eclipse to create the files and debug them. My problem now is that I try to run the Client_1.java file and I get a javax.naming.NoInitialContextException when I try to run it.
Here is my code:
package com.titan.clients;
import com.titan.interfaces.*;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
public class Client_1
{
public static void main(String [] args)
{
try
{
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("java:comp/env/ejb/Cabin");
CabinHome home = (CabinHome)
PortableRemoteObject.narrow(ref,CabinHome.class);
Cabin 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);
Cabin 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 javax.naming.NamingException
{
return new InitialContext();
//**** context initialized by jndi.properties file
/* Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "localhost:1099");
return new InitialContext(p);
*/
}
}
I try to run this file as an application and can not get this to work. What is wrong