Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.naming.NoInitialContextException

 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chandana nannapaneni
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made some changes in the Administrative Console and my code is working now. Thankyou Reza and JaiKiran for your help.

Regards,
Chandana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic