• Post Reply Bookmark Topic Watch Topic
  • New Topic

confusion: javax.naming.InitialContext vs java.util.Properties

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out what JNDI brings over normal properties files. Specifically in a Tomcat/glassfish world. I'm not trying to use any fancy stuff, no RMI, LDAP, etc.

It looks like JNDI and InitialContext are more EE like, but I can't understand the difference. Or when you would use one rather than the other.

I've written some sample code, looks like:


when I debug it, I can see that the properties "myProps" has the hashtable/map, and has pulled the proper key/value pairs from the jndi.properties file. But as soon as I touch the 'ic' object, I get an exception. javax.naming.NoInitialContextException

When I read the API, it says to properly initialize it, but I can see the real and proper values in the hashmap.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused about the question, mainly because of the reference to "myProps". What is it?

Keeping that aside, you are right about the InitialContext being more EE like. The InitialContext provides a way to access a JNDI (store) which can reside on some server. The JNDI store can contain objects that are bound to keys (in very simple terms - key/value pairs). Note that the objects bound to a JNDI store need not just be strings but can be anything else. The Context/InitialContext provides a way for clients to lookup those objects from servers.

On the other hand property files just contain key/value mappings for strings.

I hope i understood the question right and this answer clears some confusion. If not, feel free to post back with questions
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:I'm a bit confused about the question, mainly because of the reference to "myProps". What is it?

Its the internal hashmap in the InitialContext object.
When debugging, you can clearly see that it has values. Yet when you try to access them, it throws an exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!