Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI Lookup Basics

 
john hartley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I apologize in advance for asking a question that may have an obvious answer).
I am getting familiar with JMS/JNDI as part of an enhancement to a middleware java application, (non-J2EE).
Is it always required that a JNDI "client" know the class name of the context factory? If not always, then when? I have not seen a good explanation of this simple but subtle characteristic of JNDI usage.
<background>
Most of the example code that I have seen that involves JNDI lookups, begins with specifying the InitialContextFactory class name in the environment properties passed to the InitialContext constructor.
(I have some sample code that runs without specifying the factory class, so I know that it works either way depending on conditions).
To me, this seems strange that a client trying to lookup some JNDI references would need to have such implementation-specific information. Consider a JMS client that just wants to access a queue. The client isn't interested in the type of JNDI provider, just getting access to the queue.
</background>

TIA
jrh
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1st off - this IS J2EE. JMS is part of the J2EE spec.
The code that you've seen is wrong if it has the context factory class specified. It may fly in an example, but not in the real world.
In the real world, when you use JNDI, the application server executing the code should already have these properties set. If not in an app server, then you should use the "jndi.properties" file in the JRE directory tree to specify the implementation. Beginners tend to just hard code examples.
Again, the appserver should take care of this.
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, you are correct. Some of the code you are reading is older. A recent version of the spec calls for vendors supporting just

Try it and I expect it will work for you. YMMV
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notion that JMS need a application server to get it working is wrong.
It is just that app servers like Weblogic gives more reliable support for classloading etc for object messaging.
Please don't give a impression that JMS has no life outside a app server since it can be achieved other ways.
Kishore.
 
john hartley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies!
The confusion starts when you search out some real examples, even on the actual Sun website:
http://java.sun.com/products/jndi/tutorial/basics/prepare/initial.html
...as well as on the IBM examples that I have found. It just seems to me that you would not want to require the class name and you seem to agree.
Still, can anyone give me a real-world example in which you would want to have the applications specify the factory class?
And yes, JMS is within the J2EE realm, but you can use JMS without coding real J2EE objects. You don't need JNDI either but I thought I might use the most standardized and abstract approach that I can.
Thanks again,
jrh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic