Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNDI configuration/lookup in Glassfish

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:

enter image description here

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:

  • java:global/arizona/arizona/quartz_enabled
  • java:module/arizona/quartz_enabled
  • java:module/arizona/arizona/quartz_enabled

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?

like image 877
George Armhold Avatar asked Mar 11 '11 21:03

George Armhold


People also ask

What is a JNDI lookup?

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.

What is JNDI lookup class used for?

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.

What is a JNDI string?

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.

What does Jndi mean?

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.


1 Answers

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

like image 121
BRF Avatar answered Oct 07 '22 22:10

BRF