EJBUtils.java

   import javax.naming.*;
   import java.util.Hashtable;
   
   class EJBUtils {

     public static Object jndi_lookup(String name, Class resultClass) {

       // Set up environment for creating initial context
       Hashtable env = new Hashtable(11);

       // Define the nameserver - see note 1 below
       env.put(Context.PROVIDER_URL,
         "iiop://wibble.wobble.com:900");

       // Define the initial context factory -see note 2
       env.put(Context.INITIAL_CONTEXT_FACTORY,
         "com.sun.jndi.cosnaming.CNCtxFactory");
       
       try {

         // Create the initial context
         Context ctx = new InitialContext(env);

         // Lookup the object
         Object tempObject = ctx.lookup(name);

         // Narrow that to the requested class
         return javax.rmi.PortableRemoteObject.narrow(tempObject,resultClass);

       } catch (NamingException ne) {
         System.err.println("EJBUtils.jndi_lookup() failed:");
         ne.printStackTrace();
       }
       return null;
     }

   }

  
Note:
  1. Here we define the nameserver that will be used to lookup beans as "iiop://wibble.wobble.com:900". This value should be the name of your nameserver, and must match the java.naming.provider.url that was defined in the CICS JVM properties file, so that the client looks up the bean on the same nameserver it was published into by CICS. See Defining name servers for information about using name servers.
  2. Here we define the initial context factory for your client environment. you should set it to the value required by your client environment. The example shows the value you would set when using the ORB included with the IBM SDK. If your client is a java application or enterprise bean running in CICS® Transaction Server for z/OS®, Version 2, then you should not specify an initial context factory here, but should allow it to default to com.ibm.websphere.naming.wsnInitialContextFactory.