I have deployed a stateless session bean EmployeeEJB in OC4J. I have tested that the servlet, which is within the same OC4J, can obtain the remote home reference to the EmployeeEJB.
But when I wrote another servlet, which is located in Apache tomcat, to obtain the remote home reference to EmployeeEJB. It fails when the program starts to lookup through JNDI. Part of exception that I got is shown as follow:
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.EjbFactory.getObjectInstance(EjbFactory.java:184)
The following shows the coding which I try to obtain the remote reference for the EJB
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "pho5930");
env.put(Context.PROVIDER_URL, "ormi://192.168.32.129:23791/employee");
try{
Context context = new InitialContext(env);
Object homeObject = context.lookup("java:comp/env/EmployeeBean");
// Narrow the reference to EmployeeHome.
EmployeeHome home =
(EmployeeHome) PortableRemoteObject.narrow(homeObject, EmployeeHome.class);
// Create remote object and narrow the reference to Employee.
Employee remote =
(Employee) PortableRemoteObject.narrow(home.create(), Employee.class);
Can you know the reason why I got this exception ?