I'm having trouble getting some basic JNDI configuration going in Glassfish.
I have what I think ought to be a simple task: at run time, determine if a particular property is set to true or not. I think this is a good application of JNDI, but can't seem to get the path correct between the app server and my servlet code.
Here's how I have configured the property in Glassfish:
In my servlet code, I'm trying to look up the value with:
Boolean enabled = (Boolean) ctx.lookup("java:global/arizona/quartz_enabled");
In addition to this path, I've also tried the following without success:
My app is named "arizona", but deployed to the root context, if that matters.
I'm sure it's just a simple matter of figuring out the proper namespace to reach the property, but I feel like I'm just shooting in the dark trying to find it. Is there a simple way to browse the JNDI tree in Glassfish?
The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and resources (in the form of Java objects) via a name.
The Java Naming and Directory Interface (JNDI) provides consistent use of naming and/or directory services as a Java API. This interface can be used for binding objects, looking up or querying objects, as well as detecting changes on the same objects.
It is an API to providing access to a directory service, that is, a service mapping name (strings) with objects, reference to remote objects or simple data. This is called binding. The set of bindings is called the context. Applications use the JNDI interface to access resources.
JNDI Names and Resources JNDI is the acronym for the Java Naming and Directory Interface API. By making calls to this API, applications locate resources and other program objects. A resource is a program object that provides connections to systems, such as database servers and messaging systems.
When looking up a JNDI resource created in the server, it's JNDI name is exactly what you entered as the name on the server. IE:
Boolean enabled = (Boolean)ctx.lookup("arizona");
For conventions on JNDI names and some example code on how to look everything up see this page:
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-howto.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With