客户端代码:
InitialContext ctx = new InitialContext();
TestRemote b=(TestRemote) ctx.lookup("xx"); //xx为全局jndi
ejb端:
@Remote(TestRemote.class)
@Local(TestLocal.class)
@Stateless(mappedName="xx") //此处就是全局jndi
public class TestBean implements TestLocal,TestRemote{
@Override
public String run() {
return "this is testBean;";
}
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
}
客户端环境的配置:
项目引入class path %glassfishv3_home%/modules/gf-client.jar。注意是引入,而不是拷贝过来,因为gf-client.jar会用到基于glassfish_home的一些其他jar。
将要用到的ejb的接口添加到项目中,不像jboss通过build path 里add project引入,必须拷过来,要不然glassfish找不到。
这样就完了。