Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes javax.naming.NoInitialContextException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "javax.naming.NoInitialContextException" Watch "javax.naming.NoInitialContextException" New topic
Author

javax.naming.NoInitialContextException

chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
Hi,

I am trying to run a sample JMS application from java.sun.com(for j2ee 1.3.1). But I am using j2ee 5.I compiled the sender and receiver programs. I started the server using the command "start-appserv" and then added a jms destinaton using "create-jmsdest --desttype=queue MyQueue". These command were succesfully run.Then I tried to run the sender program using the command "java -Djms.propertes=c:\sun\appserver\ config\jms_client.properties SimpleQueueReceiver MyQueue 3"(This command is given in the tutorial).Here MyQueue is the queue name and 3 is the number of messages.

I got the following exception.

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

Also, I dont find "jms_client.properties" file in j2ee 5 package.
Can someone help me.

Thanks,
Chandana.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Chandana,

Kindly look through past posts dealing with similar issues. In short, you are missing the jndi.properties file in the classpath.

Best regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
Reza,

Thankyou for the reply.It worked. But now i am getting the following exception.

JNDI API lookup failed:javax.naming.NameNotFoundException: QueueConnectionFactory not found.

Should I add anything to the default jndi.properties file?

Regards,
Chandana.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

You probably are using an incorrect jndiname to lookup the connection factory. Depending on which application server you are using, you can check the JNDI tree to see what name the connection factory is bound to and then use that jndiname in your code.

[My Blog] [JavaRanch Journal]
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39

Thankyou JaiKiran for the reply. I added an instance of QueueConnectionFactory through the Administrative Console. I also added an instance of physical destination of type queue called "MyQueue". The program is now identifying QueueConnectionFactory.But it is showing an exception for MyQueue as,

javax.naming.NameNotFoundException: MyQueue not found.
Exception in thread "main" java.lang.UnsupportedOperationException
at com.sun.messaging.jmq.jmsclient.MessageProducerImpl.send(MessageProducerImpl.java:597)
at com.sun.messaging.jmq.jmsclient.QueueSenderImpl.send(QueueSenderImpl.java:97)

I added MyQueue as a physical destination but still it is not identifying. As a result I am getting error when I try to send messages into "MyQueue".

Regards,
Chandana.
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
I made some changes in the Administrative Console and my code is working now. Thankyou Reza and JaiKiran for your help.

Regards,
Chandana
 
Don't get me started about those stupid light bulbs.
 
subject: javax.naming.NoInitialContextException
 
Similar Threads
JMS - JNDI API lookup failed
JMS Message Destination Reference Exception
JMS problem
JNDI lookup for JMS...URGENT!
Unable to push messages in JBoss-JMS queue