File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes JNDI lookup for JMS...URGENT! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI lookup for JMS...URGENT!" Watch "JNDI lookup for JMS...URGENT!" New topic

JNDI lookup for JMS...URGENT!

meenakshi ashokkumar

Joined: Mar 07, 2004
Posts: 22
I'm using J2EE SDK1.4 to work some basic examples on JMS.
In all examples that i see on sun tutorials, the syntax they use for lookup is as below:
jndiContext =new InitialContext();
There is no hard coding for the Initial Context Factory.
However when i execute the examples it gives me an exception as below:
roperties SimpleQueueReceiver MyQueue
Queue name is MyQueue
JNDI API lookup failed:javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
which i infer means that the initial context was not created.
How do i go abt with this?
Where is the properties file located in the J2EE SDK?
Also if i need to hard code it how can i go about it?
Also if i need to do lookup on some other container like eg weblogic 8.1 or websphere 5.0 where is the properties file located? How to go abt it?
Sorry, i know thats toooooo may questions. But hope someone can help. This is VERY URGENT!!!
Dm Laf

Joined: Mar 23, 2004
Posts: 10
Apparently your project needs to read a file called in order to access your server. Now depending on the server, different contexts are developed.
If you are using JBoss, a file should be saved in your classes folder and it should look like this:
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
meenakshi ashokkumar

Joined: Mar 07, 2004
Posts: 22
i tried that with the following code for j2ee ri
Properties p = new Properties();
jndiContext =new InitialContext(p);
But it results in the following error!
D:\examples\JMS>java SimpleQueueReceiver MyQueue
Queue name is MyQueue
Could not create JNDI API
context:javax.naming.NoInitialContextException: Cannot instantiate class
: com.sun.jndi.cosnaming.CNCtx [Root exception is java.lang.IllegalAccessExcepti
on: Class javax.naming.spi.NamingManager can not access a member of class
n.jndi.cosnaming.CNCtx with modifiers "private"]
If there is a mistake in the Initial context factory name or url name can someone help??
Dm Laf

Joined: Mar 23, 2004
Posts: 10
You probably need to include in your project's classpath all the jars which are located in your server's libs directory
I agree. Here's the link:
subject: JNDI lookup for JMS...URGENT!
It's not a secret anymore!