• Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.naming. exception  RSS feed

 
Graham Thorpe
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am getting following exception while running jms program


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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:256)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:293)
at javax.naming.InitialContext.lookup(InitialContext.java:360)
at Sender.main(Sender.java:29)



THis is the code

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Sender {
public static void main(String[] args) {
System.out.println("Starting...");

QueueConnectionFactory aQCF = null;
QueueConnection aQC = null;
QueueSession aQS = null;
QueueSender aSender = null;
try {
InitialContext aIC = new InitialContext();
System.out.println("DEli---->" + aIC);
aQCF = (QueueConnectionFactory) aIC.lookup("QueueConnectionFactory");
System.out.println("DEli---->"+aQCF);
aQC = aQCF.createQueueConnection();
aQS = aQC.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue aQueue = (Queue) aIC.lookup("Queue");
aSender = aQS.createSender(aQueue);
aQC.start();
for (int i = 0; i < 10; i++) {
aSender.send(aQS.createObjectMessage(new Integer(i)));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (aSender != null) {
aSender.close();
}
if (aQS != null) {
aQS.close();
}
if (aQC != null) {
aQC.stop();
aQC.close();
}
} catch (JMSException e) {
e.printStackTrace();
}
}

System.out.println("Ending...");
}
}


I created QueueConnectionFactory and QUeue jndi names also.
I am using wsad5.1.
Can u pls help me out ...
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set the Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL. The documentation for WebSphere should give you the information of what needs to be done.
http://publib.boulder.ibm.com/infocenter/wasinfo/v5r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/tnam_develop_naming.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!