/** * DemoClient -- demonstrates using a minimal * Java application to talk to the DemoBean * stateless session bean */ package ejb.demo4; import javax.naming.*; import javax.rmi.*; import javax.ejb.*; import java.util.*; /** * Demo2Client demonstrates using a minimal stateless * session bean. * Remember view session beans as an extension of your * client running in the server. */ public class Demo4Client { static public void main( String[] args ) { try { // Create A Demo3Bean object, in the server // Note: the name of the class corresponds to the // JNDI property declared in the // DeploymentDescriptor // From DeploymentDescriptor ... // beanHomeName demo3.Demo3Home Properties env = new Properties(); env.put( "java.naming.factory.initial", "desisoft.ejb.client.JRMPFactory" ); env.put( "desisoft.ejb.nameServer1", "localhost:2050" ); Context ctx = new InitialContext(env); Demo4Home home = (Demo4Home) PortableRemoteObject.narrow( ctx.lookup( "Demo4" ), Demo4Home.class ); // Now you have a reference to the Demo3Home object // factory use it to ask the container to create an // instance of the Demo3 bean Demo4 bean = home.create(); // Here is the call that executes the method on the // server side object System.out.println(bean.demoSelect()); } catch (Exception ex) { ex.printStackTrace(); } } }