|
The Java Naming and Directory Interface (JNDI)
An Introduction |
|
Prof. David Bernstein |
| Computer Science Department |
| bernstdh@jmu.edu |
javax.naming Packagejavax.naming.directory Package
Map<String, Object> environment;
environment = new HashMap<String, Object>;
environment.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL,
"ldap://localhost:22801/o=Cartoons");
try
{
Context context = new InitialContext(environment);
LdapContext result = (LdapContext) context.lookup("cn=Barney Rubble,ou=People");
// Use the result
context.close();
}
catch (NamingException ne)
{
// Handle the exception
}
CourseDatabase db;
try
{
db = (CourseDatabase)Naming.lookup("rmi://localhost:22801/CourseDatabase");
// Use the result
}
catch (NamingException ne)
{
// Handle the exception
}