import javax.ejb.Remote;
@Remote
public interface IHelloEJBService {
public String sayHelloEJB(String name);
}HelloEJBService.java代码如下:
package com.test.ejb;
import javax.ejb.Stateless;
@Stateless
public class HelloEJBService implements IHelloEJBService { public String sayHelloEJB(String name) {
String msg = "hello" + name + ", Welcome to EJB world!";
System.out.print(msg);
return msg;
}
}
这个服务能够成功的发布到jboss5.0上又建立了java工程,把加入了ejb要求的client下面的所有的包。
public class TestClient {
private static Context context;
/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Context ctx = getInitialContext();
Object object = ctx.lookup("HelloEJBService/remote");
IHelloEJBService service= (IHelloEJBService)PortableRemoteObject.narrow(object, IHelloEJBService.class);
System.out.println(service.sayHelloEJB("Client "));
}
catch(Exception e)
{
e.printStackTrace();
}
}

/** 
 * 获得初始化JNDI的上下文,Jboss实现
 */
protected static Context getInitialContext() throws Exception
{
if(context == null)
{
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
props.put(Context.PROVIDER_URL, "jnp://localhost:1090");
context = new InitialContext(props);
}
return context;
}

}客户端运行后就没有反映了。请问各位是什么原因?