/** * DemoClient -- demonstrates using a minimal * Java application to talk to the DemoBean * stateless session bean */ package ejb.demo2; 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 Demo2Client { static public void main( String[] args ) { try { // Create A Demo2Bean object, in the server // Note: the name of the class corresponds to the // JNDI property declared in the // DeploymentDescriptor // From DeploymentDescriptor ... // beanHomeName demo2.Demo2Home 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); Demo2Home home = (Demo2Home) PortableRemoteObject.narrow( ctx.lookup( "Demo2" ), Demo2Home.class ); // Now you have a reference to the Demo2Home object // factory use it to ask the container to create an // instance of the Demo2 bean Demo2 bean = home.create("xxx"); System.out.println(bean.getID()); // Here is the call that executes the method on the // server side object bean.setID("yyy"); System.out.println(bean.getID()); } catch (Exception ex) { ex.printStackTrace(); } } }