NDI(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API。命名服务将名称和对象联系起来,使得我们可以用名称访问对象。
下面这个小实例,在运行之前,需要把fscontext.jar和providerutil.jar这里两个jar包加入到CLASSPATH中
public class Lookup {
public static void main(String[] args) {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
String name = "C://ecclient";
try {
// Create the initial context
Context ctx = new InitialContext(env);
// Look up an object
Object obj = ctx.lookup(name);
// print the result
System.out.println(name + " is bound to: " + obj + "/t"
+ obj.getClass());
} catch (NamingException e) {
System.err.println("Problem looking up " + name + ": " + e);
}
}
}
该贴由hui.chen转至本版2014-11-11 15:06:55
该贴由hui.chen转至本版2014-11-11 15:08:04