packagebr.com.tutorial;importbr.com.teste.HelloBeanRemote;importjavax.naming.InitialContext;importjavax.naming.NamingException;publicclassEjbCliente{publicstaticvoidmain(String[]args){EjbClienteclient=newEjbCliente();client.connect();}publicvoidconnect(){try{Thread.currentThread().setContextClassLoader(getClass().getClassLoader());/* ? If GlassFish ? */InitialContextctx=newInitialContext();HelloBeanRemotehelloRemote=(HelloBeanRemote)ctx.lookup("java:global/AgoraVai/HelloBean");System.out.println(helloRemote.test());// Deve ser utilizado a interface e não a implementação.}catch(NamingExceptione){e.printStackTrace();}}}
No Bean…
packagebr.com.teste;importjavax.ejb.Stateless;/***SessionBeanimplementationclassHelloBean*/@Stateless(name="HelloBean",mappedName="HelloBean")publicclassHelloBeanimplementsHelloBeanRemote{/***Defaultconstructor.*/publicHelloBean(){//TODOAuto-generatedconstructorstub}publicStringtest(){return"Remote is Ready";}}