I'm following the tutorial: https://docs.oracle.com/javase/tutorial/jndi/index.html
My adventure started while setting a JNDI name for a datasource with the WildFly application server. The name started with "java:/". I was curious on what it was and how it worked.
I have Apache Directory LDAP server setup locally and I'm able to connect to it with:
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=JNDITutorial");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
try {
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("cn=Rosanna Lee,ou=People");
} catch (NamingException e) {
e.printStackTrace();
}
My confusion is the JNDI name "java:/".
Can someone please explain what "java:/" is and how I can use JNDI to interact with it?
My assumption is its a directory located somewhere on my computer.
Thank you.
The explanation is in the name: JNDI is the "Java Naming and Directory Interface". It is part of the Java EE specification and provides an API for java clients to discover and look up data and objects by name. These objects are accessible via certain contexts, e.g.
ref: http://docs.oracle.com/cd/E19798-01/821-1841/girdr/index.html
As Pawel noted in his comment, the Wildfly docs are very helpful here:
The Java EE platform specification defines the following JNDI contexts:
In addition to the standard namespaces, WildFly also provides the following two global namespaces:
So "java:/" is just a global namespace (and context) in Wildfly and should be confused with a folder. It is simply a "named address" in a directory to access objects and services like JDBC, EJB, LDAP, etc.
For further information, the Java EE spec is useful: