Forums Register Login

JNDI Lookup Basics

+Pie Number of slices to send: Send
(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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 769 times.
Similar Threads
Spring+JMS+OC4J
ClassCastException JMSConnectionFactory
JmsConnectionFactory
JMS Destination not being found
Jboss MQ ConnectionFactory being returned null
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:57:49.