Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI Lookup Basics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI Lookup Basics" Watch "JNDI Lookup Basics" New topic
Author

JNDI Lookup Basics

john hartley
Greenhorn

Joined: Oct 22, 2003
Posts: 5
(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

Joined: Feb 28, 2003
Posts: 227
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

Joined: Feb 22, 2002
Posts: 1551
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

Joined: Jul 10, 2001
Posts: 1934
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.


Kishore
SCJP, blog
john hartley
Greenhorn

Joined: Oct 22, 2003
Posts: 5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI Lookup Basics
 
Similar Threads
JmsConnectionFactory
Spring+JMS+OC4J
ClassCastException JMSConnectionFactory
Jboss MQ ConnectionFactory being returned null
JMS Destination not being found