这样调用EJB出错了,那位大哥给看一下
package com.EJB.TEST;
import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloClient {
////远程接口
private com.EJB.TEST.HelloEJBHome getHome() throws NamingException {
return (com.EJB.TEST.HelloEJBHome) getContext().lookup(
com.EJB.TEST.HelloEJBHome.JNDI_NAME);
}
////本地接口
private com.EJB.TEST.HelloEJBLocalHome getLocalHome() throws NamingException {
return (com.EJB.TEST.HelloEJBLocalHome) getContext().lookup(
com.EJB.TEST.HelloEJBLocalHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(
InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public void testBean() {
try {
com.EJB.TEST.HelloEJB myBean = getHome().create();
com.EJB.TEST.HelloEJBLocal myLbean = getLocalHome().create();
//--------------------------------------
//This is the place you make your calls.
System.out.println(myBean.getHello());
System.out.println(myLbean.getTest());
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
HelloClient test = new HelloClient();
test.testBean();
}
}