The initial context and lookup are performed in a static
code block.
Example:
static {
try {
initialize();
} catch (Exception e) {
System.out.println("Caught Exception: " +
e.toString());
e.printStackTrace();
}
}
private static void initialize() throws Exception {
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
props.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
InitialContext ctx = new
InitialContext(props);
Object home =
ctx.lookup("cell/nodes/MYNODE/servers/server1/MyEJB");
/* do something with the object after this point*/
} |